My first "role" isn't running

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

  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:

`

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.

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:

`

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:

`

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 or vaults? That might be what you need.

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. :slight_smile: