# My first "role" isn't running

**URL:** <https://forum.ansible.com/t/my-first-role-isnt-running/20913>\
**Category:** Ansible Project\
**Created:** [March 18, 2016, 12:14am UTC](https://forum.ansible.com/t/my-first-role-isnt-running/20913 "2016-03-18T00:14:48Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![Uditha\_Desilva](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@Uditha\_Desilva](https://forum.ansible.com/u/Uditha_Desilva)\
**Post date:** [March 19, 2016, 12:04am UTC](https://forum.ansible.com/t/my-first-role-isnt-running/20913/21 "2016-03-19T00:04:52Z")

</div>

That “when” should be checking for “testservers” (plural).

---

<div class="post-metadata">

**Author:** ![Mike\_Biancaniello](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mike\_Biancaniello](https://forum.ansible.com/u/Mike_Biancaniello)\
**Post date:** [March 21, 2016, 2:48pm UTC](https://forum.ansible.com/t/my-first-role-isnt-running/20913/22 "2016-03-21T14:48:00Z")

</div>

1. what Uditha said about ‘testservers’.
2. By “use multiple plays”, I meant to create one play that specifies hosts: testservers, another play that specifies hosts: dev-servers, and a third that specifies hosts: prod-servers.  
Then, have specific tasks for those servers.

Now, re-looking at your playbook, I realize that I had forgotten that you were using a role for this, so separating this into multiple plays would be more complicated because you want the role to act differently depending on the group. In general, this makes the role less portable because it requires that these groups be defined.

So, if you wanted to go down this road, you could either split your role into multiple roles or split your tasks/main.yml into multiple files (this might be overkill for what you want to do, but I’m including it here for completeness):

e.g.  
tasks/prod.yml: tasks to run on all prod-servers  
tasks/dev.yml: tasks to run on all dev-servers  
tasks/test.yml: task to run on all testservers

tasks/main.yml:

`

---

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [March 22, 2016, 8:01pm UTC](https://forum.ansible.com/t/my-first-role-isnt-running/20913/23 "2016-03-22T20:01:55Z")

</div>

Hi Mike,

Thanks for the suggestions. I tried to implement what you mentioned and I ended up breaking everything. I am completely lost with this. I am just going to have to start over at this point. Between sanitizing the data to post here and then trying to translate your suggestions back to what it really is on my end keeps getting more and more complicated. Somewhere along the line, I’ve lost the translation of what you are suggestion vs how I am actually writing it.

---

<div class="post-metadata">

**Author:** ![Mike\_Biancaniello](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mike\_Biancaniello](https://forum.ansible.com/u/Mike_Biancaniello)\
**Post date:** [March 22, 2016, 8:37pm UTC](https://forum.ansible.com/t/my-first-role-isnt-running/20913/24 "2016-03-22T20:37:26Z")

</div>

like I said, since you’ve put this into a role, “separating this into multiple plays would be more complicated”, so you’re better off not splitting it up and instead, doing what you were doing

copied from your earlier post (with the typo pointed out by Uditha corrected:

In app\_install\_main.yml:

`

---

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [March 22, 2016, 11:30pm UTC](https://forum.ansible.com/t/my-first-role-isnt-running/20913/25 "2016-03-22T23:30:44Z")

</div>

Mike,

Thanks for your patience and assistance. I wanted to do it the way you suggested so that I get in the habit of crafting my roles that can be useful in other ways later. With that said, I think I am getting the hang of what you are saying. I started completely over and separated my roles. I also changed my naming convention on everything so that things don’t get lost in translation here. So, this is what I have so far:

This is what my directory structure now looks like. If you notice, I created a directory called **powerbroker,** which is essentially my project. Then, I created a sub-dir in there called **powerbroker\_install** because I’ll eventually create another called **powerbroker\_uninstall** later. Within **powerbroker\_install** I created three roles with **ansible-galaxy init** _role\_name_ for dev|prod|test. Then, I have my host file, called **powerbroker\_hosts** and my **site.yml** right under the parent directory **powerbroker\_install**.

Here is a view:

`

roles  
└── powerbroker  
├── powerbroker\_install  
│ ├── pb\_install\_dev  
│ │ ├── README.md  
│ │ ├── defaults  
│ │ │ └── main.yml  
│ │ ├── files  
│ │ ├── handlers  
│ │ │ └── main.yml  
│ │ ├── meta  
│ │ │ └── main.yml  
│ │ ├── tasks  
│ │ │ └── main.yml  
│ │ ├── templates  
│ │ ├── tests  
│ │ │ ├── inventory  
│ │ │ └── test.yml  
│ │ └── vars  
│ │ └── main.yml  
│ ├── pb\_install\_prod  
│ │ ├── README.md  
│ │ ├── defaults  
│ │ │ └── main.yml  
│ │ ├── files  
│ │ ├── handlers  
│ │ │ └── main.yml  
│ │ ├── meta  
│ │ │ └── main.yml  
│ │ ├── tasks  
│ │ │ └── main.yml  
│ │ ├── templates  
│ │ ├── tests  
│ │ │ ├── inventory  
│ │ │ └── test.yml  
│ │ └── vars  
│ │ └── main.yml  
│ ├── pb\_install\_test  
│ │ ├── README.md  
│ │ ├── defaults  
│ │ │ └── main.yml  
│ │ ├── files  
│ │ ├── handlers  
│ │ │ └── main.yml  
│ │ ├── meta  
│ │ │ └── main.yml  
│ │ ├── tasks  
│ │ │ └── main.yml  
│ │ ├── templates  
│ │ ├── tests  
│ │ │ ├── inventory  
│ │ │ └── test.yml  
│ │ └── vars  
│ │ └── main.yml  
│ ├── powerbroker\_hosts  
│ └── site.yml

`

Legend:  
blue are the project and subdir of the project  
green are the roles  
yellow are the files I touched

So far, I have only worked in **pb\_install\_test**. The only file I touched here is the following:

- pb\_install\_test/tasks/main.yml  
Here is the content of the file:

`

---

<div class="post-metadata">

**Author:** ![Mike\_Biancaniello](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mike\_Biancaniello](https://forum.ansible.com/u/Mike_Biancaniello)\
**Post date:** [March 23, 2016, 1:44pm UTC](https://forum.ansible.com/t/my-first-role-isnt-running/20913/26 "2016-03-23T13:44:20Z")

</div>

I’m actually surprised that this tree worked; I would have expected ‘roles’ to need to be under powerbroker\_install (i.e. powerbroker/powerbroker\_install/roles/pb\_install\_dev, etc), but glad that things are working for you.

For passwords, are you familiar with [prompts](http://docs.ansible.com/ansible/playbooks_prompts.html) or [vaults](http://docs.ansible.com/ansible/playbooks_vault.html)? That might be what you need.

---

<div class="post-metadata">

**Author:** ![Gilberto\_Valentin](https://avatars.discourse-cdn.com/v4/letter/g/b4bc9f/32.png) [@Gilberto\_Valentin](https://forum.ansible.com/u/Gilberto_Valentin)\
**Post date:** [March 23, 2016, 2:12pm UTC](https://forum.ansible.com/t/my-first-role-isnt-running/20913/27 "2016-03-23T14:12:41Z")

</div>

Mike,

So the roles directory is something I created manually. I saw this on a video tutorial directly made from Ansible and the instructor was creating these manually and then initiating the roles from within the roles directly. I applied the same concept and it worked :). I’ll def. check out prompts and vaults. As you can see, I am already using vars\_prompt in my **site.yml**.

Again, thanks a bunch for your help. I finally got what I needed from this thread. Thanks to Uditha for assisting as well. 🙂

[Previous page](https://forum.ansible.com/t/my-first-role-isnt-running/20913.md?page=1)
