3

I am looking for a way for config management with Ansible.

I have the structure repo/1.2.3.4/file.conf.

Can Ansible get the IP 1.2.3.4 per host and deploy the file to the host? Using a variable would make the config easier.

- copy: src=/repo/$IP/file.conf dest=/etc/file.conf owner=foo group=foo mode=0644
wishi
  • 211
  • 1
  • 2
  • 8

1 Answers1

7

Yes, you can do that with Ansible. Ansible geathers facts of the system before every run. You can check these facts about the system with the setup module like this:

ansible hostname -m setup

Check the documentation for more information.

You are looking for the default ip4 address I assume. Which would be ansible_default_ipv4. You can access the value of the variable like this:

- copy: src=/repo/{{ ansible_default_ipv4.address }}/file.conf dest=/etc/file.conf owner=foo group=foo mode=0644
Henrik Pingel
  • 8,676
  • 2
  • 24
  • 38