P11
(P)
July 19, 2013, 10:44am
1
Hi all,
I have just discovered ansible and I must admit in certain tasks it this way easier to use ansible than puppet
It is really stunning how easy are some tasks - thanks guys
I am trying to get some data from nodes. I have just run
ansible -m setup node100
but I get output in json (I guess):
node100 | success >> {
āansible_factsā: {
āansible_all_ipv4_addressesā: [
āx.x.x.xā
],
āansible_architectureā: āx86_64ā,
ā¦
ā¦
Is there any easy way to read data from particular fields, i.e.:
var1 = ansible_facts ā ansible_all_ipv4_addresses
Python-native way:
(var1, var2, var3) = (ansible_facts ā ansible_all_ipv4_addresses, ansible_facts ā ā¦, ansible_facts ā ā¦)
would be ideal
Thanks
Przemek
If you want to use this in a playbook or template, this is pretty straightforward.
Jinja2 evaluation is basically Python. The only thing is you canāt do list comprehensions.
First element:
{{ ansible_all_ipv4_addresses[0] }}
P11
(P)
July 19, 2013, 11:48am
3
At first I wanted to use it in the CLI (listing some facts about nodes) so I guess I need to download some external json parser.
Am I right ?
Regarding using it in a playbook/template: can you provide simple but full example how to use it ?
āRegarding using it in a playbook/template: can you provide simple but full example how to use it ?ā
http://ansibleworks.com/docs
P11
(P)
July 19, 2013, 12:54pm
5
Does anybody know how to parse the output from the following command ?
ansible groupofhosts -m setup -a āfilter=some_filterā
?
Why do you want to parse the output of this command?
P11
(P)
July 19, 2013, 2:40pm
7
To gather config data from nodes for further analysis.
Ok, so the API is great for that.
You also have --tree mode to dump things into individual JSON files per host.
P11
(P)
July 19, 2013, 3:13pm
9
Where I could read about it ?
Any example program ?
ansible with the --help flag, then just try the option.
It will output JSON files into the specified directory with one file per hostname.
P11
(P)
July 19, 2013, 4:06pm
11
Oh I see Michael - I am testing the ātreeā option now
I was asking about API: docs + examples.
Yeah /usr/bin/ansible is a pretty self explanatory example of the Runner API.
I would look at that closely.