Havin difficulties for my first role - newb question

hello all,

I’m a Ansible newbie and i’m trying to run a playbook with a role but cant figure out what wrong with it.
i’m have in my home folder 2 folders: ansible-role-VMware & ansible-VMware.
In ansible-VMware, i have a yml file which is deploy.yml:

That path is all the places that Ansible will look for roles. Your role is not in any of those places.

First read this:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html

​Look at the “role directory structure” on that page. In that structure, common and webserver are roles.

In other words, a role is not a simple yaml file; a role rolename is a collection of files under a directory called rolename in one of the directories in the role path.

So your first problem is that your directory ansible-role-VMware is not one of the directories in the roles path. You can fix this either by adding ansible-role-VMware’s fully-qualified path to the roles-path variable in your ansible.cfg file, or by putting your role in one of the directories that is in your roles path already, such as in ansible-VMWare.

The second problem is that your file deployova.yml is not in the correct place in the directory structure. You can fix that by creating ansible-VMware/roles/tasks and putting it in there.

The​third problem is not really a problem, but if you don’t have multiple files that you will want to choose between in the same role, you might as well call your file “main.yaml” so that Ansible will find it automatically. Then you can leave out the “tasks_from” directive.

​Regards, K.

Hello Karl,

Thanks for helping me.
My role is here:
/ansible-role-VMware/tasks/deployova.yml

I tried to add in the ansible.cfg ( the one in the ansible project , not the global one which is in /etc the role path) as shown below:

[defaults]
inventory = inventory.ini
host_key_checking = False
roles_path = /home/user/ansible-role-VMware

with no luck, i tried alos to put it in the ansible folder, still no luck

thanks

correction:

Hello Karl,

Thanks for helping me.
My role is here:
/ansible-role-VMware/tasks/deployova.yml

I tried to add in the ansible.cfg ( the one in the ansible project , not the global one which is in /etc the role path) as shown below:

[defaults]
inventory = inventory.ini
host_key_checking = False
roles_path = /home/user/ansible-role-VMware

with no luck, i tried also to put it in the /etc ansible folder, still no luck

thanks

​I think you are getting confused. Let's work from your home directory.
Everything from now on will happen in your home directory or below it. Make
sure you have set up /etc/ansible.cfg correctly for your needs OR that you
have a suitable ansible.cfg in your home directory.

First we go to your home directory:

cd

Then we create a place for your playbooks and roles:

mkdir ansible
mkdir ansible/playbooks
mkdir ansible/playbooks/roles

Then we create the role directory structure:

cd ansible/playbooks/roles
mkdir deployova
mkdir deployova/tasks

And we put your existing tasks in the right place:

cp /wherever/it/is/deployova.yml deployova/tasks/main.yaml

Then we go back to the playbooks directory:

cd ..

And create a playbook to use your role. We create myplaybook.yaml with this
content:

Thanks Carl, by moving roles into the folder, its working now.

i’ll code what i need with this method and i will give a look later on how to use the requierement.yml.

Thanks for your help.