The documented feature is listed under behaviors:

"Any copy, script, template or include tasks (in the role) can reference
files in roles/x/{files,templates,tasks}/ (dir depends on task) without
having to path them relatively or absolutely"

Based on this I would expect a filename reference to look in
"roles/x/templates" until it found the template file.

I can duplicate the file for lower roles, but I would rather parameterize
it and have the stated functionality work to find it in the templates
folder of the other role.


On Mon, Aug 22, 2016 at 12:55 PM, Dick Davies <[email protected]>
wrote:

> I'm not seeing the documented feature you're describing at the link
> you posted, and to my knowledge
> Anisble has never searching other roles templates/ for templates.
>
> If I was tackling this problem, I'd have the php role contain the
> templates it needs.
> You already know the nginx role has been applied, so you know where to put
> them.
>
> Handlers and vars from the nginx dependency are visible when you apply
> the php role,
> so you can find the right place to put your configs and bounce nginx
> if you need to easily
> enough.
>
> On 22 August 2016 at 15:47, Daniel Watrous <[email protected]>
> wrote:
> > It does have its own templates directory, but that directory doesn't
> have a
> > file of that name. I'm wondering how I can get the documented
> functionality
> > that would have ansible look in the other templates directories until it
> > finds that file.
> >
> > Otherwise, is there some way to accomplish what I am trying to do?
> >
> > Daniel
> >
> >
> > On Aug 22, 2016 4:14 AM, "Dick Davies" <[email protected]> wrote:
> >
> > 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 a topic in the
> > Google Groups "Ansible Project" group.
> > To unsubscribe from this topic, visit
> > https://groups.google.com/d/topic/ansible-project/
> Mniko9GHPCI/unsubscribe.
> > To unsubscribe from this group and all its topics, 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.
> >
> >
> > --
> > 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/
> CAHSC4g2MSgo2-pnQ8_QTji1E3%3Dssr3ZyZjab0RHYzPv-AH0%2Bmw%40mail.gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/ansible-project/Mniko9GHPCI/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAK5eLPSc3QFRTsWADu1FsBD1NLn31
> tNjgEaDNk6tHEuCLVcNHA%40mail.gmail.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/CAHSC4g29SjSxS7%2BZJ%2BsRY%2B2WEx-wX_RtuEYkb7296QBtLWozgw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to