Using variable substitution with replace module and regex

24 views
Skip to first unread message

Biswajit

unread,
Aug 1, 2016, 10:12:49 AM8/1/16
to Ansible Project
Hi,

I have two register variable in a play and want to replace one with another in a play. 
_______________

 - name: Editing  the file 

      replace:

      dest=/some/path

      regexp=^"{{ result.stdout }}."

      replace="{{ result2.stdout }}."

      backup=yes

____________


I want to replace occurrences of {{result.stdout }} with {{result2.stdout}} in a file. How can I do that ? 

Brian Coca

unread,
Feb 9, 2017, 10:30:02 PM2/9/17
to Ansible Project
The way your are doing it seems ok, except you are formating it wrong

either use this form:

- name: Editing the file
replace: dest=/some/path regexp=^"{{ result.stdout }}."
replace="{{ result2.stdout }}." backup=yes

or this one:

- name: Editing the file
replace:
dest: /some/path
regexp: ^"{{ result.stdout }}."
replace: "{{ result2.stdout }}."
backup: yes


----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages