Hi,
I"m trying to use Ansible magic var inventory_hostname along with
ansible_fqdn fact. I have a playbook that will update the hostname of the
system based on the entry in the inventory file and later it will use
ansible_fqdn value to configure a file.
Unfortunately the ansible_fqdn keeps the initial value when I start running
the plabook even if later on I manually gather facts again. The correct
value is displayed if I run the same playbook again after the first run. It
seems to me that for some reason the manual facts gathering (setup:) is not
working :
"""
- hosts: all
tasks:
- name: Gathering Ansible facts
setup:
- name: update the hostname
hostname: name="{{ inventory_hostname }}"
- name: boot persist the hostname
lineinfile: dest=/etc/sysconfig/network
regexp=^HOSTNAME=
line=HOSTNAME={{ inventory_hostname }}
state=present
- name: add the hostname to the hosts file
lineinfile: dest=/etc/hosts
regexp="^127\.0\.0\.1(.*)"
line="127.0.0.1{{'\t'}}{{ inventory_hostname }}
localhost.localdomain localhost"
state=present
backrefs=yes
- name: Print ansible_fqdn
debug: msg="ansible_fqdn is {{ ansible_fqdn }}"
"""
Any ideas ??
Regards,
N.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/400627b7-9b02-45fd-bf77-579c3c87e27d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.