ansible setup ๋ชจ๋๋ก facts ์์งํ๊ธฐ
ansible facts ๋
ansible facts ๋ remote host ์ ๋ํ ์ ๋ณด๋ฅผ ์๋ฏธํ๋ฉฐ ๋ฐฐํฌํ ์ข ๋ฅ, ๋ฒ์ , IP Address, file system ์ ๋ณด๋ฑ์ ํฌํจํฉ๋๋ค.
ansible ์ ์คํํ๋ฉด ์๋์ผ๋ก remote host ์ ๋ํ ์ ๋ณด๋ฅผ ์์งํ๋ฉฐ ์์งํ ์ ๋ณด๋ ansible_ ์ด๋ผ๋ ์ ๋์ฌ๋ฅผ ๋ถ์ฌ์ ์ ์ฅํฉ๋๋ค.
๋ค์ playbook ์ ์คํํ๋ฉด ์๊ฒฉ ์์คํ ์ ๋ํ ์ ๋ณด๋ฅผ ansible_facts ๋ณ์์ ์ ์ฅํ ํ์ ํฐ๋ฏธ๋์ ์ถ๋ ฅํฉ๋๋ค.
--- - name: gather facts hosts: localhost tasks: - name: Print all available facts ansible.builtin.debug: var: ansible_facts
$ ansible-playbook gather_facts.yml PLAY [gather facts] ************************************************************ TASK [Gathering Facts] ********************************************************* ok: [localhost] TASK [Print all available facts] *********************************************** ok: [localhost] => { "ansible_facts": { "all_ipv4_addresses": [ p192.168.187.200" ], "all_ipv6_addresses": [ "fe80::b76f:65c7:7205:dcc2" ], "ansible_local": {}, "apparmor": { "status": "disabled" },
setup ๋ชจ๋
ansible ์ playbook ์คํ์ ์๋์ผ๋ก fact ๋ฅผ ์์งํ๊ณ ์ ์ฅํฉ๋๋ค.
๋ง์ฝ playbook ์ ์์ฑํ์ง ์๊ณ ๊ฐ๋จํ๊ฒ fact ๋ง ์ถ๋ ฅํ๋ ค๋ฉด builtin ๋ชจ๋์ธ setup ์ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
$ ansible -m setup localhost
ํน์ fact ๋ง ์๊ณ ์ถ์ ๊ฒฝ์ฐ pipe ๋ก ์ฐ๊ฒฐํด์ grep ์ ์คํํ๋ฉด ๋ฉ๋๋ค.
$ ansible -m setup localhost | grep distribution "ansible_distribution": "CentOS", "ansible_distribution_file_parsed": true, "ansible_distribution_file_path": "/etc/redhat-release", "ansible_distribution_file_variety": "RedHat", "ansible_distribution_major_version": "8", "ansible_distribution_release": "Core", "ansible_distribution_version": "8.0",