Thanks a lot James, I guess I'm using the default connection type.
Didn't know I could use set_fact to override discovered values, that will
be quite handy .
Regards,
N.
On Thursday, November 20, 2014 6:26:42 PM UTC+2, James Cammarata wrote:
>
> Which connection type are you using? If you're using the default
> ("smart"), which will use SSH on most recent versions of Linux (Fedora,
> Ubuntu) and Mac OSX, the ControlPersist option will leave the SSH
> connection open to the target host, so the current hostname of the session
> will continue to be used. As I said previously, I would recommend using
> set_fact so you don't have to re-gather facts in this situation.
>
> Thanks!
>
> On Thu, Nov 20, 2014 at 10:22 AM, Nicolas G <[email protected]
> <javascript:>> wrote:
>
>> 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] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/47512810-7972-49e7-94e8-621db1767c93%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/47512810-7972-49e7-94e8-621db1767c93%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/2f78e931-901f-475b-af50-a9eb8fccc6ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.