check for FQDN

24 views
Skip to first unread message

John.1209

unread,
May 31, 2016, 3:19:30 PM5/31/16
to Ansible Project
I need to ensure that the /etc/sysconfig/network file contains the FQDN on a good number of hosts.  I think the lineinfile module would be helpful here.  But I'm sure how to write the Ansible script to do so.  Any advice?

Thanks in advance.

Johannes Kastl

unread,
May 31, 2016, 3:34:22 PM5/31/16
to ansible...@googlegroups.com
Start with:
https://gist.github.com/muloka/7687250
https://docs.ansible.com/ansible/lineinfile_module.html

Rough draft (untested):
###############

- fail: msg="Variable ansible_fqdn is not set"
when: ansible_fqdn is undefind

- name: Test lineinfile
lineinfile: dest=/etc/sysconfig/network regexp=^XYZ line="{{
ansible_fqdn }}"

###############

The most important part is the regexp, which tells the lineinfile
module which line you want to change.

Johannes

signature.asc
Reply all
Reply to author
Forward
0 new messages