Possible problem

#file: cmservers.yml - hosts: cmservers tasks: - include_vars: /var/cm/local/ansible/vars/cmusers.yml - debug: var=users roles: - ansible-users-master 

I find that role tasks are performed first, but first you need to define a list of users, which does not happen. Any help was appreciated.

+4
source share
2 answers

You can use pre_tasks to make sure that some roles are performed before the role and post_tasks to make sure that some tasks are performed after the role is applied. Therefore, changing tasks to pre_tasks will fix the problem.

 - hosts: cmservers pre_tasks: - include_vars: /var/cm/local/ansible/vars/cmusers.yml - debug: var=users roles: - ansible-users-master 

You can learn more about documentation in more detail.

+1
source

Alternatively, you can use the vars_files directive in the tutorial. This is convenient when you store variables in the vars/main.yml , but there are some additional variables or some private data (you can use Ansible Vault for this) to enable at run time the playbook.

 #file: cmservers.yml - hosts: cmservers vars_files: - /var/cm/local/ansible/vars/cmusers.yml roles: - ansible-users-master 

Since include_vars is a task, it’s better to use it in / hanlders roles and use vars_files in playbooks instead. It is also easier to pass Ansible command line variables using vars_files . For more information see: http://docs.ansible.com/ansible/playbooks_variables.html

+2
source

All Articles