Esteemed Collegues, I have created a Playbook to replcae the Entry in a file using a lineinfile module, while i tried running it run and replace in entry on the one host while not on the another host, i don't understand why? as it doesn't report any error even on the debug mode. Do i need to have some another regex pattern.
---
- name: Playbook to replace the line in file
hosts: all
remote_user: root
gather_facts: False
serial: 4
tasks:
- name: replace line
lineinfile:
dest: /tmp/test_master
state: present
regexp: '^passwd: files ldap' # line to be replaced
line: 'passwd_compat: ldap' # new line which is replace existing , the one above
backrefs: yes
backup: yes
register: nss
- name: replace line
debug: var=nss
My Hostvar Inventory File:
# test_regex_hosts
[hosts]
Dev-mauj
Dev-pranjala
[hosts:vars]
ansible_ssh_user=root
ansible_ssh_private_key_file=/Dev/ansibleSpotin
Destination File contents:
$ cat /tmp/test_master
#
# nsswitch.conf
#
passwd: files ldap
shadow: files ldap
group: files ldap
hosts: files dns
bootparams: files
ethers: files
netmasks: files ldap
networks: files ldap
protocols: files ldap
rpc: files ldap
services: files ldap
netgroup: files ldap
publickey: files ldap
automount: files ldap
printers: user files ldap
sudoers: ldap
aliases: files ldap
Note: ansible 2.4
You need to account for white space. Try:
regexp: '^passwd:.*files ldap'