I am too used to typing outside of browsers. Let's try this again.
According to the module docs
<http://docs.ansible.com/ansible/lineinfile_module.html>, there is
different behaviour whether you are replacing an existing line (backrefs)
or adding a non-existent line (insertafter or insertbefore).
Insertafter/insertbefore will add a new line but not remove the old one.
If you want to replace an existing line, you can use backrefs. However, if
the regexp line doesn't match, it won't add the replacement line:
Adding to Johannes example:
> - name: "Replace hostname with FQDN"
> lineinfile:
> dest=/etc/sysconfig/network
> line="HOSTNAME={{ ansible_fqdn }}"
backrefs=yes
> regexp="^HOSTNAME=.*"
> state=present
On Friday, June 3, 2016 at 11:20:11 AM UTC-5, Joanna Delaporte wrote:
>
> In the setup module (get_facts), Ansible should be detecting an FQDN that
> you can access with '{{ ansible_fqdn }}'
>
> I would use the lineinfile module. A rough draft (untested) without
>> correct indentation:
>>
>> - name: "Ensure FQDN is present"
>> lineinfile:
>> dest=/etc/sysconfig/network
>> line="HOSTNAME={{ ansible_fqdn }}"
>
>
>
>>
>> regexp="^HOSTNAME=.*"
>> insertafter=EOF
>> state=present
>>
>> This has to be adapted, of course. Replace FQDN with your real fqdn.
>>
>> Basically this looks for a line beginning with "HOSTNAME" (the regexp
>> part) and replaces it with the line "HOSTNAME=FQDN". If there is no
>> line matching the regexp, it puts the line at the end of the file.
>>
>> Johannes
>>
>>
>>
>>
--
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/f5f40562-3160-4faf-811d-30efb484d5e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.