Hi,
below is the playbook.i wanna multiple commands in a single task using
loop (with_items) and copy the stdout of each loop for every hosts in a
file.
=======================
ansible --version
ansible 1.7.2
========================
=============================================================
---
- name: All the hosts
hosts: all
gather_facts: false
connection: paramiko
tasks:
- name: items
raw: "{{ item }}"
register: linux_os
with_items:
- uname -a
- netstat -rn
- name: Do something with each result
local_action: template src= {{ item.stdout }}
dest=/home/openstack/Documents/{{inventory_hostname}}.txt
with_items: "{{ linux_os.stdout_lines }}"
====================================================================
Output:
PLAY [All the hosts]
**********************************************************
TASK: [sh clock]
**************************************************************
ok: [192.168.1.191] => (item=uname -a)
ok: [192.168.1.191] => (item=cat /etc/resolv.conf)
TASK: [debug var=linux_os]
****************************************************
ok: [192.168.1.191] => {
"linux_os": {
"changed": false,
"msg": "All items completed",
"results": [
{
"invocation": {
"module_args": "uname -a",
"module_name": "raw"
},
"item": "uname -a",
"rc": 0,
"stderr": "",
"stdout": "Linux splunk-server 3.2.0-65-generic #98-Ubuntu
SMP Wed Jun 11 20:27:07 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux\n"
},
{
"invocation": {
"module_args": "cat /etc/resolv.conf",
"module_name": "raw"
},
"item": "cat /etc/resolv.conf",
"rc": 0,
"stderr": "",
"stdout": "# Dynamic resolv.conf(5) file for glibc
resolver(3) generated by resolvconf(8)\n# DO NOT EDIT THIS FILE BY HAND
-- YOUR CHANGES WILL BE OVERWRITTEN\nnameserver 127.0.0.1\nsearch
localdomain\n"
}
]
}
}
==========
Error:
TASK: [copy]
******************************************************************
fatal: [192.168.1.191 -> 127.0.0.1] => {'msg': 'AnsibleError: unable to
read /home/openstack/Documents/uname', 'failed': True}
fatal: [192.168.1.191 -> 127.0.0.1] => {'msg': 'One or more items failed.',
'failed': True, 'changed': False, 'results': [{'msg': 'AnsibleError: unable
to read /home/openstack/Documents/uname', 'failed': True}]}
FATAL: all hosts have already failed -- aborting
PLAY RECAP
********************************************************************
to retry, use: --limit @/root/test.retry
192.168.1.191 : ok=2 changed=0 unreachable=1 failed=0
----------------------------------------------------------------------------------------------
I wanna output as:
Linux splunk-server 3.2.0-65-generic #98-Ubuntu SMP Wed Jun 11 20:27:07 UTC
2014 x86_64 x86_64 x86_64 GNU/Linux
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by
resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1
search localdomain"
--------------------------------------------------------
Thanks
Pavan
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/7551dc41-5da8-4a63-83d0-59f627142cec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.