環境の情報を取得してansibleで利用できる。
puppetだとfacterに相当。facterが入っているとその値も取ってくるようだ。
- hosts: localhost gather_facts: False
ansible -m setup -a "filter=ansible_local" localhost localhost | SUCCESS => { "ansible_facts": { "ansible_local": { "example": { "general": { "asdf": "1", "bar": "2" } } } }, "changed": false }
例:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 127.0.0.1 test.example.com example.com
sudo mkdir /etc/ansible/facts.d/ sudo vi /etc/ansible/facts.d/example.fact -- [general] asdf=1 bar=2 -- ansible -m setup localhost | less ... "ansible_facts": { ... "ansible_local": { "example": { "general": { "asdf": "1", "bar": "2" } } }, ...
ansible -m setup localhost
[defaults] stdout_callback=yaml bin_ansible_callbacks=True
名前等に日付や時刻を入れたい時に便利。
ansible -m setup localhost | less ... "ansible_date_time": { "date": "2018-11-19", "day": "19", "epoch": "1542599604", "hour": "12", "iso8601": "2018-11-19T03:53:24Z", "iso8601_basic": "20181119T125324856687", "iso8601_basic_short": "20181119T125324", "iso8601_micro": "2018-11-19T03:53:24.856865Z", "minute": "53", "month": "11", "second": "24", "time": "12:53:24", "tz": "JST", "tz_offset": "+0900", "weekday": "月曜日", "weekday_number": "1", "weeknumber": "47", "year": "2018" },