It is actually possible to use set_fact with json data already, or to use info
from json data for pretty much anything. You just need to use the from_json
filter.
- set_fact:
hostname: "{{ (user_data.content|from_json).hostname }}"
or in the example given:
- name: Set hostname from user data
command: "hostname {{ (user_data.content|from_json).hostname }}"
when: user_data is defined
Although 2 things to mention:
1) As mentioned, I do think that the ec2_facts module already grabs user-data
<https://github.com/ansible/ansible/blob/devel/library/cloud/ec2_facts#L61>
If I am reading the code correctly, would end up looking like:
{{ hostvars[inventory_hostname]['ansible_ec2_user-data']['hostname'] }}
2) Instead of issuing a hostname change via the command module, look at the
hostname module <http://docs.ansible.com/hostname_module.html>
--
Matt Martz
[email protected]
On March 17, 2014 at 6:49:59 AM, Dag Wieers ([email protected]) wrote:
On Mon, 17 Mar 2014, Ben Turner wrote:
> Looks like all "user-data" in AWS is just a "string" at the end of the day.
>
> So there is no way for Ansible to parse that string and pull out values,
> without a third-party module such as
> https://github.com/jpmens/ansible-ec2-userdata say ?
It would be a very simple improvement to set_fact to allow a string to
become a json-object, however the syntax of set_fact was made so that
every parameter is a fact name.
However a set_fact_from_json module would be super-easy to implement, so
that you can combine it with uri (or other registered variables).
Another option is to extend the uri module with an option like:
content_as_json=yes
My prefered solution is to include this in the inventory step (outside of
Ansible) so that it can be processed asynchronous (and cached) to Ansible.
--
-- dag wieers, [email protected], http://dag.wieers.com/
-- dagit linux solutions, [email protected], http://dagit.net/
[Any errors in spelling, tact or fact are transmission errors]
--
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/alpine.LRH.2.02.1403171242390.6649%40pikachu.3ti.be.
For more options, visit https://groups.google.com/d/optout.
--
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/etPan.5326eaf8.6b8b4567.4542%40mobiletuvix.rackspace.corp.
For more options, visit https://groups.google.com/d/optout.