From 3d2f023cb27126e879ac3522169cf813507b58ba Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sun, 15 Dec 2013 04:49:50 +0100 Subject: Force expansion of escape sequences. By using double quoted scalars, cf. https://groups.google.com/forum/#!topic/ansible-project/ZaB6o-eqDzw --- roles/common/tasks/hosts.yml | 30 ++++++++++++++++-------------- roles/common/templates/etc/hostname.j2 | 1 - roles/common/templates/etc/mailname.j2 | 1 - 3 files changed, 16 insertions(+), 16 deletions(-) delete mode 100644 roles/common/templates/etc/hostname.j2 delete mode 100644 roles/common/templates/etc/mailname.j2 diff --git a/roles/common/tasks/hosts.yml b/roles/common/tasks/hosts.yml index f818635..b8e5931 100644 --- a/roles/common/tasks/hosts.yml +++ b/roles/common/tasks/hosts.yml @@ -1,29 +1,31 @@ - name: Set hostname - template: src=etc/hostname.j2 - dest=/etc/hostname - owner=root group=root - mode=0644 + # Use double quoted scalars to force expansion of escape sequences + # cf. https://groups.google.com/forum/#!topic/ansible-project/ZaB6o-eqDzw + copy: "content='{{ inventory_hostname_short }}\n' + dest=/etc/hostname + owner=root group=root + mode=0644" tags: hostname notify: - Refresh hostname - name: Set mailname - template: src=etc/mailname.j2 - dest=/etc/mailname - owner=root group=root - mode=0644 + copy: "content='{{ inventory_hostname }}\n' + dest=/etc/mailname + owner=root group=root + mode=0644" tags: mailname - name: Fix /etc/hosts (1) - lineinfile: dest=/etc/hosts create=yes - regexp="^127\.0\.0\.1\s+" - line="127.0.0.1 localhost" + lineinfile: "dest=/etc/hosts create=yes + regexp='^127\\.0\\.0\\.1\\s+' + line='127.0.0.1\tlocalhost'" tags: hosts - name: Fix /etc/hosts (2) - lineinfile: dest=/etc/hosts create=yes - regexp="^127\.0\.1\.1\s+" - line="127.0.1.1 {{ inventory_hostname }} {{ inventory_hostname_short }}" + lineinfile: "dest=/etc/hosts create=yes + regexp='^127\\.0\\.1\\.1\\s+' + line='127.0.1.1\t{{ inventory_hostname }} {{ inventory_hostname_short }}'" tags: hosts - meta: flush_handlers diff --git a/roles/common/templates/etc/hostname.j2 b/roles/common/templates/etc/hostname.j2 deleted file mode 100644 index 68fd234..0000000 --- a/roles/common/templates/etc/hostname.j2 +++ /dev/null @@ -1 +0,0 @@ -{{ inventory_hostname_short }} diff --git a/roles/common/templates/etc/mailname.j2 b/roles/common/templates/etc/mailname.j2 deleted file mode 100644 index 1fad51f..0000000 --- a/roles/common/templates/etc/mailname.j2 +++ /dev/null @@ -1 +0,0 @@ -{{ inventory_hostname }} -- cgit v1.2.3