Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lineinfile backrefs broken or incompatible in 1.6 #6821

Closed
josef-spak opened this issue Apr 2, 2014 · 4 comments
Closed

lineinfile backrefs broken or incompatible in 1.6 #6821

josef-spak opened this issue Apr 2, 2014 · 4 comments
Assignees
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release

Comments

@josef-spak
Copy link

Issue Type:

Bug Report

Ansible Version:
  • 'ansible 1.6 (devel fe88fcb) last updated 2014/04/02 15:10:06 (GMT +200)'
  • compared against current stable: 'ansible 1.5.4'
Environment:

Ubuntu 12.04 (both)

Summary:

There seems to be no way to use backreferences in the lineinfile module that works in both current stable and devel versions (see above).

Number of backslashes to correctly use a positional (numbered) backref:

version 1.5.4 1.6
single quotes 1 2
double quotes 1-2 3-4
Steps To Reproduce:

Use the lineinfile module with backrefs=yes like this:

# single quote version                                                          
- lineinfile: dest=/etc/php5/cli/php.ini state=present backrefs=yes 'regexp=(auto_prepend_file =)' 'line=\1 \\1 \\\1 \\\\1 /vagrant/scripts/inc.prepend.php'

# double quote version                                                          
- lineinfile: dest=/etc/php5/cli/php.ini state=present backrefs=yes 'regexp=(auto_prepend_file =)' "line=\1 \\1 \\\1 \\\\1 /vagrant/scripts/inc.prepend.php"
Expected Results:
  • At least one way to use backreferences in lineinfile module that will work in both stable and dev version of Ansible.
  • That way should be the same (or YAML equivalent) way as in the documentation at http://docs.ansible.com/lineinfile_module.html#examples - the documentation is correct for v1.6, but there's no mention of the incompatibility with previous versions
Actual Results:

The resulting line was copypasted from vim, comments added:

# single quotes in 1.5.4                                                    
auto_prepend_file = \1 \auto_prepend_file = \\1 /vagrant/scripts/inc.prepend.php

# single quotes in 1.6                                                      
^A auto_prepend_file = \^A \1 /vagrant/scripts/inc.prepend.php              

# double quotes in 1.5.4                                                    
auto_prepend_file = auto_prepend_file = \1 \1 /vagrant/scripts/inc.prepend.php

# double quotes in 1.6                                                      
^A ^A auto_prepend_file = auto_prepend_file = /vagrant/scripts/inc.prepend.php
  • The CTRL+A character in 1.6 is weird and most likely a bug
  • There is no way to insert a backslash in the resulting line using v1.6 with double quotes
  • Can't find any backward compatibility even if I try really really hard :)
@josef-spak
Copy link
Author

Additional notes:

  • I'm sure it is almost always a better idea to use the template module instead - but this is still broken
  • If I try using 'line=\2' incorrectly in 1.6 instead of \1, The CTRL+A in output becomes CTRL+B

@josef-spak
Copy link
Author

The change seems to originate from 2bfaacd according to git-bisect. #5679 #6448

2bfaacd17063ed52ceca53f55861acb7ff655c66 is the first bad commit
commit 2bfaacd17063ed52ceca53f55861acb7ff655c66
Author: Jakub Jirutka <jakub@jirutka.cz>
Date:   Wed Mar 12 18:21:53 2014 +0100

    Fix #5679 again after recent changes in core

:040000 040000 00d76a0298764193e6c0faecafd3def05f1bca74 caf72582641059c85c5453f9720869967c88c842 M  library
:040000 040000 209a0f0242229d90669d59f3ca0616964df0c424 b4eb84a557be36a5c282558c9be3f1520df5121f M  test

@jimi-c jimi-c self-assigned this Apr 3, 2014
@jimi-c jimi-c closed this as completed in b73cddc Apr 7, 2014
@jimi-c
Copy link
Member

jimi-c commented Apr 7, 2014

I've gone ahead and reverted the above commit, due to the fact that when using the decode() call things like \1 are interpretted as an octal escape sequence, so we can't really use that function effectively there. Thanks!

@jjshoe
Copy link
Contributor

jjshoe commented Apr 22, 2014

@jimi-c - Looks like the docs need a revert too: #7119

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 6, 2018
@ansible ansible locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release
Projects
None yet
Development

No branches or pull requests

5 participants