ansible block of code

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I need to create an xml formated file in ansible. The file contains <> and spaces.
When I run the playbook without the <> or any white spaces between lines in it, the playbook creates the files.
How can I create a file with the following context
blockinfile:
path: /tmp/testfile.txt
content: |
<example1>
this is test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
ansible
add a comment |Â
up vote
0
down vote
favorite
I need to create an xml formated file in ansible. The file contains <> and spaces.
When I run the playbook without the <> or any white spaces between lines in it, the playbook creates the files.
How can I create a file with the following context
blockinfile:
path: /tmp/testfile.txt
content: |
<example1>
this is test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
ansible
Did Lewis' post answer your question? If so, mark the answer as "accepted" by klicking the check mark sign to the left of the answer!
â mhutter
Sep 18 at 9:02
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to create an xml formated file in ansible. The file contains <> and spaces.
When I run the playbook without the <> or any white spaces between lines in it, the playbook creates the files.
How can I create a file with the following context
blockinfile:
path: /tmp/testfile.txt
content: |
<example1>
this is test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
ansible
I need to create an xml formated file in ansible. The file contains <> and spaces.
When I run the playbook without the <> or any white spaces between lines in it, the playbook creates the files.
How can I create a file with the following context
blockinfile:
path: /tmp/testfile.txt
content: |
<example1>
this is test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
ansible
ansible
asked Sep 10 at 17:25
user2236794
262
262
Did Lewis' post answer your question? If so, mark the answer as "accepted" by klicking the check mark sign to the left of the answer!
â mhutter
Sep 18 at 9:02
add a comment |Â
Did Lewis' post answer your question? If so, mark the answer as "accepted" by klicking the check mark sign to the left of the answer!
â mhutter
Sep 18 at 9:02
Did Lewis' post answer your question? If so, mark the answer as "accepted" by klicking the check mark sign to the left of the answer!
â mhutter
Sep 18 at 9:02
Did Lewis' post answer your question? If so, mark the answer as "accepted" by klicking the check mark sign to the left of the answer!
â mhutter
Sep 18 at 9:02
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
Look at the block section of blockinfile, https://docs.ansible.com/ansible/2.5/modules/blockinfile_module.html
Here is an example role
user1$ cat testblock/tasks/main.yml
---
- name: Testing blockinfile
blockinfile:
path: /tmp/testfile.txt
block: |
<example1>
this is a test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
...
And here is the playbook:
user1$ cat testblock.yml
---
- hosts: localhost
roles:
- testblock
...
Running ansible-playbook ./testblock.yml produces the following file:
user1$ cat /tmp/testfile.txt
# BEGIN ANSIBLE MANAGED BLOCK
<example1>
this is a test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
# END ANSIBLE MANAGED BLOCK
Hope this helps.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Look at the block section of blockinfile, https://docs.ansible.com/ansible/2.5/modules/blockinfile_module.html
Here is an example role
user1$ cat testblock/tasks/main.yml
---
- name: Testing blockinfile
blockinfile:
path: /tmp/testfile.txt
block: |
<example1>
this is a test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
...
And here is the playbook:
user1$ cat testblock.yml
---
- hosts: localhost
roles:
- testblock
...
Running ansible-playbook ./testblock.yml produces the following file:
user1$ cat /tmp/testfile.txt
# BEGIN ANSIBLE MANAGED BLOCK
<example1>
this is a test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
# END ANSIBLE MANAGED BLOCK
Hope this helps.
add a comment |Â
up vote
2
down vote
Look at the block section of blockinfile, https://docs.ansible.com/ansible/2.5/modules/blockinfile_module.html
Here is an example role
user1$ cat testblock/tasks/main.yml
---
- name: Testing blockinfile
blockinfile:
path: /tmp/testfile.txt
block: |
<example1>
this is a test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
...
And here is the playbook:
user1$ cat testblock.yml
---
- hosts: localhost
roles:
- testblock
...
Running ansible-playbook ./testblock.yml produces the following file:
user1$ cat /tmp/testfile.txt
# BEGIN ANSIBLE MANAGED BLOCK
<example1>
this is a test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
# END ANSIBLE MANAGED BLOCK
Hope this helps.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Look at the block section of blockinfile, https://docs.ansible.com/ansible/2.5/modules/blockinfile_module.html
Here is an example role
user1$ cat testblock/tasks/main.yml
---
- name: Testing blockinfile
blockinfile:
path: /tmp/testfile.txt
block: |
<example1>
this is a test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
...
And here is the playbook:
user1$ cat testblock.yml
---
- hosts: localhost
roles:
- testblock
...
Running ansible-playbook ./testblock.yml produces the following file:
user1$ cat /tmp/testfile.txt
# BEGIN ANSIBLE MANAGED BLOCK
<example1>
this is a test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
# END ANSIBLE MANAGED BLOCK
Hope this helps.
Look at the block section of blockinfile, https://docs.ansible.com/ansible/2.5/modules/blockinfile_module.html
Here is an example role
user1$ cat testblock/tasks/main.yml
---
- name: Testing blockinfile
blockinfile:
path: /tmp/testfile.txt
block: |
<example1>
this is a test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
...
And here is the playbook:
user1$ cat testblock.yml
---
- hosts: localhost
roles:
- testblock
...
Running ansible-playbook ./testblock.yml produces the following file:
user1$ cat /tmp/testfile.txt
# BEGIN ANSIBLE MANAGED BLOCK
<example1>
this is a test1
blah
blah
</example1>
<example2>
this is test2
hello
</example2>
# END ANSIBLE MANAGED BLOCK
Hope this helps.
edited Sep 10 at 17:48
Jeff Schaller
33.1k849111
33.1k849111
answered Sep 10 at 17:40
Lewis M
3813
3813
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468061%2fansible-block-of-code%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Did Lewis' post answer your question? If so, mark the answer as "accepted" by klicking the check mark sign to the left of the answer!
â mhutter
Sep 18 at 9:02