Playbook directory organisation

137 views
Skip to first unread message

James Morgan

unread,
Jun 25, 2015, 6:22:43 AM6/25/15
to ansible...@googlegroups.com
Hi,

This has probably been covered before but I can't find any solutions.

My project pulls in roles from other projects via Maven. This means that we can have company wide roles reused.

This all works fine, all the roles are dropped into a subdirectory in roles and referenced in the playbooks.

I would like do something similar with playbooks. Whilst I can reference roles using ../roles/rolename inside a playbook in a subdirectory

None of the group_vars that are available to the top level playbooks are available to the playbook in the subdirectory

Has anybody solved this or is there a better way of organising playbooks.

Any help appreciated

Thanks

cruz....@gmail.com

unread,
Jun 26, 2015, 9:06:04 AM6/26/15
to ansible...@googlegroups.com
Hi James,

Have you set the ansible configuration file's (ansible.cfg) roles_path default setting?

If you are following the best practices documented (https://docs.ansible.com/intro_configuration.html#roles-path), it should be pulling in those group_vars variables, if the host(s) being applied to the plays/playbooks are within the defined groups that contain the variables.

Where is the group_vars folder relative to the playbooks that are not "seeing" the variables? 

To further confirm, please post an example in pastebin.

Thanks,

Cruz

James Morgan

unread,
Jun 26, 2015, 11:03:13 AM6/26/15
to ansible...@googlegroups.com
Hi,

Thanks for the info. I hadn't looked at those configs, though we can only change the configuration on certain environments. 

My layout is pretty straightforward

.
├── group_vars
│   └── all.yml
└── roles
   ├── roleA
   ├── roleB
   └── shared_roles
       ├── roleC
       └── roleD
├── playbook1.yml  <---- these pick up the group_vars
├── playbook2.yml
├── playbook3.yml
├── playbook_sub_dir
│   ├── playbook4.yml  <---- these don't pick up the group_vars
│   ├── playbook5.yml
│   └── playbook6.yml

I'll try and knock together an example. I can't include the actual project as there is a fair amount of sensitive information...

The issue is just with the playbooks in the sub directories. I can get them to hit the roles by referencing them with ../ its just the group_vars that aren't getting picked up

Im just looking to organise the playbooks as im starting to get a lot in the root directory

Thanks

James

Hagai Kariti

unread,
Jun 26, 2015, 11:17:09 AM6/26/15
to ansible...@googlegroups.com

Group vars can sit next to your inventory or next to your playbook. Looks like your current groupvars are evaluated because they sit next to yout root-dir playbooks.

You can try to put them next to your inventory so that they'll be evaluated for every pkaybook that's run with that inventory.


--
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/Kmv-TXIMDA0/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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9a1cdee4-b807-42ea-beb9-d86db7abf148%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Morgan

unread,
Jun 26, 2015, 11:28:09 AM6/26/15
to ansible...@googlegroups.com
Ok that makes sense but causes a problem for my layout. I have

.
├── group_vars
│   ├── all.yml
│   ├── groupA.yml
│   ├── groupB.yml
│   └── groupC.yml
├── inventory
│   └── ec2
│       ├── eu-west
│       │   ├── inventoryA
│       │   └── inventoryB
│       └── us-east
│           ├── inventoryA
│           └── inventoryB


There are many inventories. Currently I have all plays use the groups defined in the main group_vars. If I was to move some common groups_vars to the inventory then they would be duplicated for each inventory. Unless im missing something

I was hoping there would be a way of having ansible look at the playbook_dir instead of its current dir when evaluating the group_vars. 

J

Hagai Kariti

unread,
Jun 26, 2015, 12:08:37 PM6/26/15
to ansible...@googlegroups.com

There was another thread about that yesterday. No good option that i know of. You can try to create a link to your var files inside each invetory, or write another inventory script that includes these files.


--
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/Kmv-TXIMDA0/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.

James Morgan

unread,
Jun 26, 2015, 12:10:33 PM6/26/15
to ansible...@googlegroups.com
Ok,

 I think i'd prefer more playbooks in the playbook_dir rather than resorting to symlinks. Less likely to confuse or go wrong. 

Cheers for the info

J

ddffgpmfn

unread,
Jun 26, 2015, 12:45:07 PM6/26/15
to ansible...@googlegroups.com

James Morgan

unread,
Jun 28, 2015, 6:53:23 AM6/28/15
to ansible...@googlegroups.com
Interesting read though that seems to concern itself with the group_var / inventory layouts. I don't really have a problem there. Just the playbook sub directories not picking up the variables. If I ignore the idea of tidying playbooks by sub directory everything works well. Symlinks seem a bit dirty and error prone, though as mentioned they would be preserved by git which could work as long as they are relative.

I'll have a play. Thanks for all the advice

J

Tom Paine

unread,
Jun 29, 2015, 8:16:26 PM6/29/15
to ansible...@googlegroups.com
Have updated that thread with an inventory script that can pick up any
YAML vars files you'd like.
> --
> 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/Kmv-TXIMDA0/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.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c28559d2-b1af-424f-8710-196e84949481%40googlegroups.com.

James Morgan

unread,
Jun 30, 2015, 10:41:37 AM6/30/15
to ansible...@googlegroups.com
Interesting, thanks for the info will have a play with it.


For more options, visit https://groups.google.com/d/optout.



--
James Morgan
Principal Technologist
T:+44 208 742 1600
+44 208 987 1124
M:+44 771 727 6762
E:james....@openbet.com
W:www.openbet.com
OpenBet Ltd
Chiswick Park Building 9
566 Chiswick High Rd
London
W4 5XT
Openbet One account
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postm...@openbet.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by OpenBet for employment and security purposes. To protect the environment please do not print this e-mail unless necessary. OpenBet Ltd. Registered Office: Chiswick Park Building 9, 566 Chiswick High Road, London, W4 5XT, United Kingdom. A company registered in England and Wales. Registered no. 3134634. VAT no. GB927523612
Reply all
Reply to author
Forward
0 new messages