Sorry , the correct playbook is the one bellow, the setup module executed
before the debug action at the end:
"""
- hosts: all
tasks:
- 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: Gathering Ansible facts
setup:
- name: Print ansible_fqdn
debug: msg="ansible_fqdn is {{ ansible_fqdn }}"
"""
On Thursday, November 20, 2014 6:18:58 PM UTC+2, Nicolas G wrote:
>
> 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/47512810-7972-49e7-94e8-621db1767c93%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.