lineinfile does not expand "\t" when some conditions are met #174
Comments
Here is the additional information about quoting. I have tried other mixes of quoting. The new test data file:
And the playbook: --- # file: lineinfile.yml
- hosts: all
gather_facts: False
vars:
original_file: ./test.txt.org
target_file: ./test.txt
fresh_start: yes
tasks:
- name: copy the data file
copy: src={{ original_file }} dest={{ target_file }}
force={{ fresh_start }}
- name: case1 insert the line '...'
lineinfile: dest={{ target_file }} state=present
insertafter='\t.*single-quoted-nomix'
line='\ta line with tab 1'
regexp='a line with tab 1'
- name: case2 insert the line "..."
lineinfile: dest={{ target_file }} state=present
insertafter="\t.*double-quoted-nomix"
line="\ta line with tab 2"
regexp="a line with tab 2"
- name: case3 insert the line with '"..."'
lineinfile: dest={{ target_file }} state=present
insertafter='\t.*single-quoted-mix'
line='\ta line with "tab" 3'
regexp='a line with "tab" 3'
- name: case4 insert the line "'...'"
lineinfile: dest={{ target_file }} state=present
insertafter="\t.*double-quoted-mix"
line="\ta line with 'tab' 4"
regexp="a line with 'tab' 4"
- name: case5 insert the line with '"..."' with jinja2
lineinfile: dest={{ target_file }} state=present
insertafter='\t.*single-quoted-jinja2-mix'
line='{{ "\t" }}a line with "tab" 5'
regexp='a line with "tab" 5'
- name: case6 insert the line "'...'" with jinja2
lineinfile: dest={{ target_file }} state=present
insertafter="\t.*double-quoted-jinja2-mix"
line="{{ '\t' }}a line with 'tab' 6"
regexp="a line with 'tab' 6" The actual resulted file is here.
You can see only case4 is affected. Again, Ansible 1.7.1 ends up with all normal results (good) |
Not only \t, I can see it also for \1 when backrefs is enabled. Tested on Fedora 20. |
The issue only appears on ansible 1.7.2. ansible/ansible-modules-core#174
As an update to my previous comment, this is another example of broken lineinfile, this time for \1: ---
- hosts: localhost
connection: local
gather_facts: False
vars:
original_file: ./lineinfile_backref.txt
target_file: ./lineinfile_backref_test.txt
tasks:
- name: copy the data file
copy: src={{ original_file }} dest={{ target_file }} force=yes
- name: broken test
lineinfile: dest={{ target_file }}
backrefs=yes regexp="(^[ ]+'values'.*)\),"
line="\1 'vn')," The example file is:
The commit which introduced the regression is Reverting the patch (I tested on 1.8.2), the previous behavior is restored. Is it possible to fix that issue without breaking this? |
A fix in ansible >= 1.7.2 broke the behavior of lineinfile with regexp and backrefs in some conditions. More details here: ansible/ansible-modules-core#174 Khaleesi now requires ansible >= 1.7.2, escape the single quotes, which restore the required behavior. Please note that this change breaks lineinfile < 1.7.2. Also, preserve the spaces at the beginning of the replaced line. Change-Id: Ia2be03936630f3827fa35e05df0f90ee00d7b342
Has this issue been resolved yet? If so, in what version? |
@ansible, ping. This issue is waiting on your response. |
@ansible, ping. This issue is still waiting on your response. |
@ansible, ping. This issue is still waiting on your response. |
2 similar comments
@ansible, ping. This issue is still waiting on your response. |
@ansible, ping. This issue is still waiting on your response. |
@ansible, ping. This issue is still waiting on your response. |
This repository has been locked. All new issues and pull requests should be filed in https://github.com/ansible/ansible Please read through the repomerge page in the dev guide. The guide contains links to tools which automatically move your issue or pull request to the ansible/ansible repo. |
This issue was migrated to ansible/ansible#30225 |
Issue Type:
Bug Report
Ansible Version:
1.7.2
(1.7.1 does not have this issue)
Environment:
CentOS7 x86_64
pip install ansible for 1.7.2
yum install ansible for 1.7.1
Summary:
lineinfile fails to expand "\t" when the inserted line has "...'...'..." type of quoting.
Steps To Reproduce:
prepare the following playbook and the test data file.
Here is test.txt.org. Note: the indent is by a tab.
Then, run the playbook:
Expected Results:
The target machine should have test.txt in the home directory.
Actual Results:
The two character string "\t" is inserted instead of a tab.
The text was updated successfully, but these errors were encountered: