Hi All,
I have file below, would like to comment out the line with hmac-sha1 and uncomment like with #Commened for LINUXMSB 2013'
Interestingly if dont use loop(with_items), it works fine. When i use with with_item, it adds another escape character, Am i missing something?
Here is the code:
$ cat sshd.yml
---
- hosts: localhost
connection: local
tasks:
#- replace:
# path: sshd_config
# regexp: '(.*hmac-sha1.*)'
# replace: '#\1'
#- replace:
# path: sshd_config
# regexp: '#Commented for LINUXMSB 2013 '
- replace:
path: sshd_config
regexp: "{{item.exp}}"
replace: "{{item.rep}}"
with_items:
- { exp: '(.hmac-sha1.)', rep: '# \1' }
- { exp: '#Commented for LINUXMSB 2013 ', rep: '' }
Here is ansible run:
$ ansible-playbook sshd.yml
[WARNING]: Could not match supplied host pattern, ignoring: all
[WARNING]: provided hosts list is empty, only localhost is available
PLAY [localhost] ****************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************
ok: [localhost]
TASK [replace] ******************************************************************************************************************************************************
ok: [localhost] => (item={u'rep': u'#
\\1', u'exp': u'(.hmac-sha1.)'})
ok: [localhost] => (item={u'rep': u'', u'exp': u'#Commented for LINUXMSB 2013 '})
PLAY RECAP **********************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0