directory layout for grouping playbooks - ansible.cfg ?

406 views
Skip to first unread message

Torsten Reinhard

unread,
May 28, 2015, 5:50:40 AM5/28/15
to ansible...@googlegroups.com
Hi,

we have several playbooks and roles in our project so I try to organize them in that way:

\---deployment
   
\---trunk
        |   ansible.cfg
        |   app1.yml
        |   ....yml
        |   app[N].yml
       
+---files
       
+---filter_plugins
       
+---group_vars
       
+---library
       
+---playbooks
       
|   +---provisioning
       
|   |   |   binaryBuild.yml
       
|   |   |   root.yml
       
|   |   |   site.yml
       
|   |   |   user.yml
       
|   |   +---roles
        |   |   |   test-java.yml
       
|   |   |   +---java


we put the ansible.cfg to the root of our project (trunk) to keep all settings in a central place, so whenever somebody checks out that project it should be executable.

Now, when invoking

ansible-playbook -i /path/to/inventory/hosts playbooks/provisioning/site.yml

the execution faills because of missing roles, filter_plugins and so on. Ansible tries to load those relative to the playbook - and not relative to the current directory!

Only workaround I found is to add a list of settings to the ansible.cfg file:

roles_path = roles: ../roles: ../../roles
filter_plugins
= filter_plugins:../filter_plugins:../../filter_plugins:~/.ansible/plugins/filter_plugins/:/usr/share/ansible_plugins/filter_plugins

Using ${ANSIBLE_HOME} in the ansible.cfg to have fixed path also did not work for me.

=> What is the "best practice" to organize real-life projects, containing a huge list of playbooks?
=> Also, where do people put their "test playbooks", for integration testing of roles ?

I dont want a solution based on
* ansible.cfg outside the project ( HOME directory or any other user dependant place)
* symlinks

I couldn´t find any hint concerning "test playbooks" and "organizing modules" in the documentation.

Thanx for any advice,

Torsten

Torsten Reinhard

unread,
May 28, 2015, 6:55:24 AM5/28/15
to ansible...@googlegroups.com
in addition, also the group_vars cannot be resolved - they are expected relative to the playbook(s) - or the inventory hosts file.

=> how do i define common group_vars/all.yml - when i want to structure my playbooks in (sub) directories ?

Regards, Torsten

Ulrich Hochholdinger

unread,
May 28, 2015, 11:09:06 AM5/28/15
to ansible...@googlegroups.com
Hi,
I'm also in the situation to get "many" different projects under control and use following directory structure:
- one folder per project with dependeing playbooks and roles
- global inventory with one folder per stage (since the project share hosts I made only one inventory )
- group_vars and host_vars only in inventory
- global "site.yml' including playbooks out of projects
- "only for "global_roles" I had to add one Entry in roles_path in my ansible.cfg

I don't know if this is good practice. Improvements and tips are welcome :D

Details:

site.yml example:
---
- include project1/deployment.yml
- include project2/play.yml
...

Directory-Layout:
 ansible/
├── site.yml
├── project1/
│   ├── character1.yml
│   ├── character2.yml
│   ├── config_mgmt.yml
│   ├── deployment.yml
│   ├── library/
│   │   └── module1
│   ├── roles/
│   │   ├── role1/
│   │   └── role2/
│   └── site.yml
├── project2/
│   ├── roles/
│   └──  ...
├── project3/
├── .../
├── global_roles/
│   ├── role1/
│   └── role2/
├── inventory/
│   ├── development/
│   │   ├── project1
│   │   ├── project2
│   │   ├── ....
│   │   ├── group_vars/
│   │   └── host-vars/
│   ├── integration/
│   │   └── ...
│   ├── staging/
│   └── production/


Cheers
     Ulli

Yoshi Spendiff

unread,
Jan 4, 2016, 8:50:50 PM1/4/16
to Ansible Project
Hi,

Torsten, did you ever find an answer?

It seems like it should be trivial to simply have a plays or playbooks directory, but I'm not finding a good way to do it...

Breaking down into projects isn't what I'm looking for as I'd like to share roles

Regards,
Yoshi

Ben Cohen

unread,
Jan 4, 2016, 11:28:19 PM1/4/16
to ansible...@googlegroups.com
I also yearn for a solution to this problem -- I think that ansible playbooks don't compose well -- and roles are (in my opinion) a not-so-good abstraction for code re-use / process organization.  Frequently for the 'orchestration' portion of some automation I find myself needing playbooks and the only way I can write playbook logic with access to resources that is shared with other playbooks (vars, group_vars, plugins etc) is to keep them all in what becomes a giant directory of playbooks ...  Its both annoying and harder to organize/package for other users than it would be if I could compose the playbook units in a better way ...  I'd love to be able to:

(1) include a playbook from another playbook with dynamically specified hosts: eg something like: 
include: some-playbook.yml hosts={{some_host_or_group_determined_by_logic}}

(2) organize my playbooks so that I can suggest to other developers which playbooks are entry points and which are only meant to be used as part of other automation pipelines -- while keeping a unified 'file/template/plugin/var_file...' search space ...
include: ./some_dir/some-playbook.yml keep_resource_search_paths=true


--
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/5f73dfaf-a13d-4336-af8d-922b3fe8fa3c%40googlegroups.com.

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

Reply all
Reply to author
Forward
0 new messages