Playbook -- How to read a value from another yaml file ?

329 views
Skip to first unread message

Darup tek

unread,
Aug 30, 2014, 2:43:19 AM8/30/14
to ansible...@googlegroups.com
I have this playbook which changes the xml file on a remote server.
This playbook needs to read a value from another yaml file.

For example source yaml file:
main.yml
cluster: onecluster
product: someproduct
....


playbook.yml
-replace: dest=/a/b/cd.xml regexp=something replace=<<< value of cluster from main.yml >>>

The  playbook.yml changes the  value as per the value from main.yml.
I cannot not hardcode that in the playbook.yml, all the values should come from central place(main.yml)

Thank you in advance.




Henry Finucane

unread,
Aug 30, 2014, 3:05:18 PM8/30/14
to ansible...@googlegroups.com
I'm not 100% sure if I understand the question, but your inventory can
associate extra yaml files with all hosts or with groups of hosts. The
documentation is fairly reasonable:
http://docs.ansible.com/intro_inventory.html (group_vars are what you
want, and are discussed at the end)

As an aside, the Ansible convention for global defaults is the "all" group.
> --
> 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/3dde3d79-10b2-4623-9a7c-8634e1c91b32%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
-----------------------
| Henry Finucane
| "I hear aphorisms are popular"
-----------------------

Darup tek

unread,
Aug 31, 2014, 2:42:34 AM8/31/14
to ansible...@googlegroups.com
Thanks, I solved the problem by using extra-vars.

Michael DeHaan

unread,
Sep 2, 2014, 6:58:01 PM9/2/14
to ansible...@googlegroups.com
vars_files:
   - /path/to/foo.yaml

Would be the most idiomatic way to read a YAML file in a playbook.




Darup tek

unread,
Sep 2, 2014, 7:23:47 PM9/2/14
to ansible...@googlegroups.com
That makes sense , I can populate the yaml before executing the playbook.
Thanks for the suggestion.


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/GFgJIDVCZvU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages