Created
July 10, 2015 14:52
Revisions
-
infernix created this gist
Jul 10, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ --- - name: Sanity check hosts: all connection: local tasks: - fail: msg="You need at least two hosts to run this play against, but more is better" when: play_hosts|length < 2 run_once: yes - name: Generate two tempfiles with run_once, and make a list hosts: all connection: local tasks: - shell: mktemp register: parallel run_once: true - shell: mktemp register: serial run_once: true - name: Write the hostname to our parallel tempfile hosts: all connection: local tasks: - lineinfile: dest={{ parallel.stdout }} line="{{ inventory_hostname }} at {{ ansible_date_time.date }} {{ ansible_date_time.time }} {{ ansible_date_time.tz }}" create=no state=present - name: Write the hostname to our serial tempfile hosts: all connection: local serial: 1 tasks: - lineinfile: dest={{ serial.stdout }} line="{{ inventory_hostname }} at {{ ansible_date_time.date }} {{ ansible_date_time.time }} {{ ansible_date_time.tz }}" create=no state=present - name: Cat both tempfiles and print them hosts: all connection: local tasks: - shell: cat {{ parallel.stdout }} register: paralleldata run_once: yes - shell: cat {{ serial.stdout }} register: serialdata run_once: yes - debug: var=paralleldata.stdout_lines run_once: yes - debug: var=serialdata.stdout_lines run_once: yes - debug: msg="Serial play has {{ serialdata.stdout_lines|length }} lines, parallel play has {{ paralleldata.stdout_lines|length }} lines" run_once: yes - fail: msg="Unexpected behaviour from lineinfiles module with connection local" when: "serialdata.stdout_lines|length != paralleldata.stdout_lines|length" run_once: yes