Hi,
I’m trying to use lineinfile module to replacing a line which matches the regular expression. The file content is:
**#TIMEZONE='America/Chicago'**
P.S. Ignore the Markdown tags
---
- hosts: servers
remote_user: root
tasks:
- name: customize timezone configuration
lineinfile: dest=/tmp/test.txt regexp="^#TIME_ZONE.*$" line="TIME_ZONE='Asia/Yakutsk'" state=present
The first playbook (above) works just fine, the result line would be TIMEZONE=‘Asia/Yakutsk’. But the result of the second playbook (below) is TIME_ZONE=Asia/Yakutsk. See? The single quote characters were missing! Why does that happen? And How Can I make the second playbook work correctly?
---
- hosts: servers
remote_user: root
tasks:
- name: customize timezone configuration
lineinfile: dest=/tmp/test.txt regexp={{ item.default }} line={{ item.custom }} state=present
with_items:
- { default: "^#TIME_ZONE.*$", custom: "TIME_ZONE='Asia/Yakutsk'" }
Ansible Version: 1.5.4
Ansible Host: Ubuntu 14.04.1 x86_64 (3.16.0-30-generic)
Manipulated Server: CentOS 7.0 x86_64 (3.10.0-123.el7)
Ansible configuration: default