raub@desktop:~/dev/ansible$ cat roles/test/tasks/file.yml
---
# File tests
- name: upload a temp file
copy:
src: testfile
dest: /tmp/testfile
- name: The contents of testfile
shell: cat /tmp/testfile
register: file_contents
- debug:
var: file_contents.stdout
- name: now change something in it
replace:
path: /tmp/testfile
regexp: '(\&)'
replace: '\&'
- name: The contents of modified testfile
shell: cat /tmp/testfile
register: file_contents
- debug:
var: file_contents.stdout
raub@desktop:~/dev/ansible$
raub@desktop:~/dev/ansible$ cat roles/test/files/testfile
This file has text & spaces
Do not ask me why
raub@desktop:~/dev/ansible$
raub@desktop:~/dev/ansible$ ansible-playbook test.yml --limit testcentos
[...]
TASK [test : upload a temp file] ***********************************************
changed: [testcentos]
TASK [test : The contents of testfile] *****************************************
changed: [testcentos]
TASK [test : debug] ************************************************************
ok: [testcentos] => {
"file_contents.stdout": "This file has text & spaces\nDo not ask me why"
}
TASK [test : now change something in it] ***************************************
changed: [testcentos]
TASK [test : The contents of modified testfile] ********************************
changed: [testcentos]
TASK [test : debug] ************************************************************
ok: [testcentos] => {
"file_contents.stdout": "This file has text \\& spaces\nDo not ask me why"
}
[root@testcentos ~]# cat /tmp/testfile
This file has text \& spaces
Do not ask me why
[root@testcentos ~]#
> To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/8cacf438-cf7e-40f2-9e39-15b0388e49f0%40googlegroups.com.