Closed jcrisologo closed 7 years ago
After goofing around a bit, I have modified the test playbook to produce the desired behavior. Within free-form arguments, you actually need to put less backslashes. This is not clear in the documentation which only states that you need more backslashes inside YAML arguments pre-2.0. Not sure if this is a bug or a documentation problem.
- hosts: localhost
connection: local
tasks:
- debug: msg={{ 'foobar' | regex_replace('^(foo)bar$', '\\1') }}
- command: echo {{ 'foobar' | regex_replace('^(foo)bar$', '\1') }}
# This example came from trying to run https://github.com/MindPointGroup/RHEL6-STIG
- debug: msg={{ 'S.5....T. /etc/rc.d/init.d/supervisord' | regex_replace('^..5......\\s+(/.+)$', '\\1') }}
- command: echo {{ 'S.5....T. /etc/rc.d/init.d/supervisord' | regex_replace('^..5......\s+(/.+)$', '\1') }}
Using /etc/ansible/ansible.cfg as config file
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": "foo"
}
TASK [command] *****************************************************************
changed: [localhost] => {"changed": true, "cmd": ["echo", "foo"], "delta": "0:00:01.003961", "end": "2016-12-06 22:26:52.873410", "rc": 0, "start": "2016-12-06 22:26:51.869449", "stderr": "", "stdout": "foo", "stdout_lines": ["foo"], "warnings": []}
TASK [debug] *******************************************************************
ok: [localhost] => {
"msg": "/etc/rc.d/init.d/supervisord"
}
TASK [command] *****************************************************************
changed: [localhost] => {"changed": true, "cmd": ["echo", "/etc/rc.d/init.d/supervisord"], "delta": "0:00:00.002626", "end": "2016-12-06 22:26:53.076810", "rc": 0, "start": "2016-12-06 22:26:53.074184", "stderr": "", "stdout": "/etc/rc.d/init.d/supervisord", "stdout_lines": ["/etc/rc.d/init.d/supervisord"], "warnings": []}
PLAY RECAP *********************************************************************
localhost : ok=5 changed=2 unreachable=0 failed=0
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.
ISSUE TYPE
COMPONENT NAME
command / shell / raw
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
N/A
SUMMARY
Regex group captures and backreferences do not seem to work properly when used with the command module, despite appearing to work with other modules.
STEPS TO REPRODUCE
Ran as 'ansible-playbook -i localhost, test.yml -vvvv'
EXPECTED RESULTS
The message printed out by the debug module should match the stdout of the command module.
ACTUAL RESULTS