Use replace module to update /etc/nsswitch.conf 19/13219/1
authorAnil Belur <abelur@linuxfoundation.org>
Mon, 29 Oct 2018 02:55:47 +0000 (12:55 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Mon, 29 Oct 2018 02:55:47 +0000 (12:55 +1000)
Use the replace module instead of calling the sed regex
directly from shell.

Change-Id: I2408c49ed2578552c924a484a58979d7b0c24ed6
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
provision/baseline.yaml

index cbfc28c..fa2de70 100644 (file)
       # Update /etc/nss-switch.conf to map hostname with IP instead of using `localhost`
       # from /etc/hosts which is required by some of the Java API's to avoid
       # Java UnknownHostException: "Name or service not known" error.
-      shell: sed -i "/^hosts:/s/$/ myhostname/" /etc/nsswitch.conf
+      replace:
+        path: /etc/nsswitch.conf
+        regexp: '^hosts:(\s+.*)?$'
+        replace: 'hosts:\1 myhostname'
+        backup: yes
       become: yes
 
     - name: Disable periodic updates