# Help organizing project and accessing paths

**URL:** <https://forum.ansible.com/t/help-organizing-project-and-accessing-paths/15786>\
**Category:** Ansible Project\
**Tags:** galaxy-ng\
**Created:** [July 27, 2014, 2:31pm UTC](https://forum.ansible.com/t/help-organizing-project-and-accessing-paths/15786 "2014-07-27T14:31:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_VanGundy](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Ryan\_VanGundy](https://forum.ansible.com/u/Ryan_VanGundy)\
**Post date:** [July 27, 2014, 2:31pm UTC](https://forum.ansible.com/t/help-organizing-project-and-accessing-paths/15786/1 "2014-07-27T14:31:45Z")

</div>

I’m working on a small Ansible project that’s a little outside its primary use-case. I’m automating the generation of new web projects in a Mac OS X dev environment. There are two objectives:

1.) Install all development tools on the local machine  
2.) Compose various projects based on small component roles/tasks

As a simple example, if you run the main playbook, it will prompt you for a project folder, install Sublime Text, NodeJS, etc., and set up all the basic files needed to begin working on a new project. Here’s a subset of my project folder:

`  
ansible-generator

> - main.yml ← Main playbook
> - apps
> - nodejs
> - tasks,vars,defaults,etc.
> - sublime
> - scaffolds
> - git
> - node
> - vagrant
> - install
> - dmg.yml  
> `

Everything under both apps and scaffolds are roles. ‘apps’ install local dev tools, and ‘scaffolds’ uses templates to set up and modify new project files (package.json, Vagrantfile, .gitignore, etc.)

I have a couple questions:

1.) Could this entire project be turned in to a role itself and be distributed on Ansible Galaxy, given its different project layout and different use-case? Since this is a project built using lots of small sub-roles, how could I run all those dependent roles from tasks/main.yml?

2.) The roles in the /apps folder need to reference tasks under the /install folder. Right now I have to use relative paths like “…/…/…/dmg.yml”. I’d rather set up a variable further up and just use “{{ installers }}/dmg.yml”, but without just setting this variable to “…/…/…” What’s the best way to get the absolute path to the root of this project? The playbook\_dir variable always returns “.”

3.) Any other thoughts on organizing my project? Is it reasonable to have roles in both /apps and /scaffolds or does this seem unwieldy compared to putting everything under a /roles folder?

Thanks! If you’d like to take a closer look at my project you can find it here: [https://github.com/rvangundy/ansible-generator](https://github.com/rvangundy/ansible-generator)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 27, 2014, 8:54pm UTC](https://forum.ansible.com/t/help-organizing-project-and-accessing-paths/15786/2 "2014-07-27T20:54:28Z")

</div>

This may be a useful resource for organization tips:

[http://docs.ansible.com/playbooks\_best\_practices.html](http://docs.ansible.com/playbooks_best_practices.html)

Also, if you haven’t seen it already, the ansible-galaxy CLI can be used to quickly stub out a role with the “init” command.

You may wish to read about role dependencies, however galaxy is not meant as a way to distribute top level playbooks - in practice, they are seldom reusable because nobody wants to install the exact same infrastructure (you’ve already made a lot of choices about Sublime and Node), whereas roles provide a more ideal chunk of reuse.

As for your directory questions try, “{{ playbookdir }}/some\_path”.

---

<div class="post-metadata">

**Author:** ![Ryan\_VanGundy](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Ryan\_VanGundy](https://forum.ansible.com/u/Ryan_VanGundy)\
**Post date:** [July 27, 2014, 9:45pm UTC](https://forum.ansible.com/t/help-organizing-project-and-accessing-paths/15786/3 "2014-07-27T21:45:39Z")

</div>

Thanks for the response.

I’m using the following task:

`

- debug: msg=“{{ playbook\_dir }}”  
`

With this output…

`ok: [localhost] => { "msg": "." }`

So it’s returning a relative path. I get this same output regardless of where I run the debug task, so this doesn’t help me point to my project root if I use the playbook\_dir variable in one of my roles or some other subdirectory. Incidentally, inventory\_dir returns an absolute path (e.g. /etc/ansible), though the inventory directory isn’t what I’m after.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 28, 2014, 2:09pm UTC](https://forum.ansible.com/t/help-organizing-project-and-accessing-paths/15786/4 "2014-07-28T14:09:29Z")

</div>

What is “ansible --version” ?

---

<div class="post-metadata">

**Author:** ![Ryan\_VanGundy](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Ryan\_VanGundy](https://forum.ansible.com/u/Ryan_VanGundy)\
**Post date:** [July 28, 2014, 7:15pm UTC](https://forum.ansible.com/t/help-organizing-project-and-accessing-paths/15786/5 "2014-07-28T19:15:21Z")

</div>

ansible 1.7

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 28, 2014, 7:39pm UTC](https://forum.ansible.com/t/help-organizing-project-and-accessing-paths/15786/6 "2014-07-28T19:39:47Z")

</div>

Ok - got it.

Sounds like a path just needs to be os.path.abspath’d somewhere.

If your 1.7 checkout is up to date, please file a github ticket so we can take a look.

Thanks!

---

<div class="post-metadata">

**Author:** ![Ryan\_VanGundy](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Ryan\_VanGundy](https://forum.ansible.com/u/Ryan_VanGundy)\
**Post date:** [July 28, 2014, 10:11pm UTC](https://forum.ansible.com/t/help-organizing-project-and-accessing-paths/15786/7 "2014-07-28T22:11:05Z")

</div>

Done.

[https://github.com/ansible/ansible/issues/8317](https://github.com/ansible/ansible/issues/8317)
