Last active
February 18, 2018 20:51
-
-
Save VireshDoshi/13bbcaf90451eb97320c502e227e2156 to your computer and use it in GitHub Desktop.
Ansible playbook with_file demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[vdo023@localhost loop_with_file]$ ansible-playbook -i "localhost," -c local ./with_files-playbook.yml | |
PLAY [localhost] ********************************************************************************************************************************** | |
TASK [Gathering Facts] **************************************************************************************************************************** | |
ok: [localhost] | |
TASK [create a file number 1 for this example] **************************************************************************************************** | |
ok: [localhost] | |
TASK [create a file number 2 for this example] **************************************************************************************************** | |
changed: [localhost] | |
TASK [loop through files and print out the content] *********************************************************************************************** | |
ok: [localhost] => (item=# BEGIN ANSIBLE MANAGED BLOCK | |
first file 2018 - viresh doshi | |
# END ANSIBLE MANAGED BLOCK) => { | |
"changed": false, | |
"item": "# BEGIN ANSIBLE MANAGED BLOCK\nfirst file 2018 - viresh doshi\n# END ANSIBLE MANAGED BLOCK", | |
"msg": "# BEGIN ANSIBLE MANAGED BLOCK\nfirst file 2018 - viresh doshi\n# END ANSIBLE MANAGED BLOCK" | |
} | |
ok: [localhost] => (item=# BEGIN ANSIBLE MANAGED BLOCK | |
second file 2018 - viresh doshi | |
# END ANSIBLE MANAGED BLOCK) => { | |
"changed": false, | |
"item": "# BEGIN ANSIBLE MANAGED BLOCK\nsecond file 2018 - viresh doshi\n# END ANSIBLE MANAGED BLOCK", | |
"msg": "# BEGIN ANSIBLE MANAGED BLOCK\nsecond file 2018 - viresh doshi\n# END ANSIBLE MANAGED BLOCK" | |
} | |
PLAY RECAP **************************************************************************************************************************************** | |
localhost : ok=4 changed=1 unreachable=0 failed=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
tasks: | |
- name: create a file number 1 for this example | |
blockinfile: | |
path: "{{playbook_dir}}/first.txt" | |
block: "first file 2018 - viresh doshi" | |
create: True | |
- name: create a file number 2 for this example | |
blockinfile: | |
path: "{{playbook_dir}}/second.txt" | |
block: "second file 2018 - viresh doshi" | |
create: True | |
# emit a debug message containing the content of each file. | |
- name: loop through files and print out the content | |
debug: | |
msg: "{{ item }}" | |
with_file: | |
- first.txt | |
- second.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment