Ansible execute each role in different host -
my intention execute each role in different host. doing simple task of downloading files in each host. have host file looks so
[groupa] 10.0.1.20 [groupb] 10.0.1.21
below main_file.yml file
--- - hosts: local connection: local gather_facts: no roles: - oracle - apache
structure of roles
main_file.yml roles |-- oracle | |-- tasks | |-- main.yml | |-- download_file.yml |-- apache | |-- tasks | |-- main.yml | |-- download_file.yml
oracle/main.yml
--- - name: downloading file in groupa hosts: groupa tasks: - include: tasks/download_file.yml
oracle/download_file.yml
--- - name: download file shell: wget http://dummyurl.com/random.sh
same steps followed apache role "groupb". when execute main_file.yml getting below error
error! no action detected in task. indicates misspelled module name, or incorrect module path. error appears have been in '/etc/ansible/roles/oracle/tasks/main.yml': line 2, column 3, may elsewhere in file depending on exact syntax problem. offending line appears be: --- - name: downloading file ^ here
in ansible there 2 levels, 1 playbook level, other 1 task level. on playbook level can specify hosts want run tasks on, under tasks level no longer possible, hosts have been specified. roles included @ tasks level, cannot have hosts declarations inside them.
you should remove hosts main.yml, , have include:
--- - name: downloading file in groupa include: download_file.yml
as roles templates specific host, if want them run on specific host include them in playbook accordingly. example in main_file.yml
can write following:
--- - hosts: groupa roles: - oracle - hosts: groupb roles: - apache - hosts: local connection: local tasks: - { debug: { msg: "tasks run locally" } }
Comments
Post a Comment