I would like to know if
- shell: >
hostname;
whoami;
and
- shell: "{{item}}"
with_items: ['hostname', 'whoami']
are equivalent? In the second example, Ansible will always use the same SSH connection for both commands (hostname, whoami)?
It seems to me that it is false...
- shell: "{{item}}"
with_items: ['export miavar=PIPPO', 'echo $miavar']
(item=export miavar=PIPPO) => {"changed": true, "cmd": "export miavar=PIPPO", "stdout": ""}
(item=echo $miavar) => {"changed": true, "cmd": "echo $miavar", "stdout": ""}
--ansible 2.1.1.0
Riccardo
Ansible runs each loop iteration as separate run, so you end up with different ssh sessions.
There are some exceptions described in ANSIBLE_SQUASH_ACTIONS variable:
"apk, apt, dnf, package, pacman, pkgng, yum, zypper"
This modules are smart enough to squash all items into a single task call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With