Roles look in their own templates/ directory for templates. The nginx
role will be applied first due to the dependency, but it has its own
templates/ directory.

On 21 August 2016 at 15:32, Daniel Watrous <[email protected]> wrote:
> I have a playbook with several roles. For example, I have an nginx role and
> a php role. Each has the typical directory structure. The nginx role has a
> template and a task for a virtualhost file that appears like this in the
> tasks
>
> - name: "Move virtual host file into place"
>   template: "src={{item.src}} dest={{item.dest}} mode={{item.mode}} owner={{
> nginx_site_user }} group={{ nginx_site_group }}"
>   with_items:
>     - dest: "{{ nginx_sites_available }}/{{ nginx_site_user }}"
>       src: "{{ nginx_vhost_file_template }}"
>       mode: 640
>   notify:
>   - restart nginx
>
> When I run the nginx role, the variable nginx_vhost_file_template is set to
> "default" and the file "roles/nginx/templates/default" exists. This works
> fine.
>
> For my PHP role, I simply want to override the nginx_vhost_file_template
> variable to point to a file "phpsitevhost" in the directory
> "roles/php/templates/phpsitevhost". The php role includes the file
> "meta/main.yml" with the following contents.
>
> ---
> dependencies:
>   - { role: nginx }
>
> Based on the documentation
> http://docs.ansible.com/ansible/playbooks_roles.html#roles, I would expect
> the template call in the nginx role to look in both "roles/nginx/templates/"
> and "roles/php/templates/". It's not working this way and instead I get
>
> TASK [nginx : Move virtual host file into place]
> *******************************
> failed: [localhost] (item={u'dest': u'/etc/nginx/sites-available/examplewp',
> u'src': u'phpsitevhost', u'group': u'examplewp', u'mode': 640, u'owner':
> u'examplewp'}) => {"failed": true, "item": {"dest":
> "/etc/nginx/sites-available/examplewp", "group": "examplewp", "mode": 640,
> "owner": "examplewp", "src": "phpsitevhost"}, "msg": "IOError: [Errno 2] No
> such file or directory: u'/home/vagrant/src/phpsitevhost'"}
>
>
> It appears to only be searching for the file in the directory where the
> playbook file is.
>
> How can I get the documented behavior where it would look for the file in
> the templates directories for all included roles?
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/b779599d-597b-4f6e-84fd-6f5918221777%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAK5eLPRYZodnJbvd7z-icgM29zajJbY-Kd%3DgEUy2yt0dcEkYOQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to