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",


๊ฐ™์ด ๋ณด๊ธฐ

Ref