Hi Nicholas, in your example above, the manual use of the setup module would have to come after the hostname entry is changed in the file. Alternatively, you could simply use a call to set_fact to override that value, so that you don't have to regather all of the facts.
On Thu, Nov 20, 2014 at 10:18 AM, Nicolas G <[email protected]> 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/400627b7-9b02-45fd-bf77-579c3c87e27d%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/400627b7-9b02-45fd-bf77-579c3c87e27d%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAMFyvFi%3D85xLkE8%2Bmd2HoOox8aGLKf3iHNHHsXLohGjANuEStw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
