0

I have a playbook which has the following content:

/home/username/project/deploybook.yml

- hosts: api_servers
  tasks:
    - import_tasks: roles/api/tasks/deploy.yml

And the task file deploy.yml imported by the plabook in the role "api" which is concerned with management of api servers:

/home/username/project/roles/api/tasks/deploy.yml

- name: copy api supervisor config to servers
  template:
    src: "{{ item }}"
    dest: "/etc/supervisor/conf.d/{{ item|basename }}.conf"
    force: yes
  with_fileglob:
    - "supervisor/*.*"
  notify: restart supervisor

The above play fails because Ansible fails to locate the config files which residese in the role's template folder at:

/home/username/project/roles/api/templates/supervisor/gunicorn.j2

Ansible is searching for the templates folder within the tasks folder and not the templates directory located in the parent folder. How to solve this?

conquester
  • 1,082
  • 2
  • 21
  • 44
  • That's **not** how you should use roles (read the [manual before posting on SO](https://docs.ansible.com/ansible/latest/playbooks_reuse_roles.html#using-roles)) and Ansible works perfectly ok here. – techraf Feb 09 '18 at 17:46
  • I think it makes sense because the deploy methodology of each group/role is different and it helps to place them where they belong. The deploy playbook in concern here just calls the deploy taskfile of that role. The management playbook can call other tasks file of that role when it needs to. – conquester Feb 09 '18 at 17:48
  • You think it makes sense, Ansible creators did not. Create your own Ansible fork and customise it to suit your taste. – techraf Feb 09 '18 at 17:49
  • Thank you for the link to the documentation. I suppose neither I am as smart as you or the Ansible creators to work on a fork. My problem is clearly due to a deficiency in understanding of the patterns of Ansible. Ansible has also been known to have lots of strange bugs because it is a new system. I just needed some pointers from someone to help me out. Thank you. – conquester Feb 09 '18 at 17:54
  • Ansible turns 6 years in two weeks and it is well documented. The only problem is that you need to read the docs and follow the examples, not write some code to your liking and expect it work. – techraf Feb 09 '18 at 18:05
  • 1
    @conquester the templates are discovered by simply referencing the name, in your case just reference the .j2, your fileglob won't help you – Ilhicas Feb 09 '18 at 19:41

0 Answers0