Hello, 
Your requirement is not clear enough. can you please elaborate more on what 
are you trying to achieve,

>> if it's possible to pass variables from playbook to role which has 
template.
if you wants to decide the template to use at run time, then you need not 
provide the complete path. Instead you may place all the templates in a 
folder inside roles. The template file can then be called in main.yml  
using a variable as shown below: 

playbook.yml
- roles:
        - { role: monit, monit_proc: "sshd",monit_ssh_port: "25"}


monit/tasks/main.yml :
   - name: Add {{ monit_proc }}
      template: 
        src: "{{monit_proc}}.cfg.j2"
        dest: /etc/monit/conf.d/{{monit_proc}}.conf


Thanks 
Soniya

On Tuesday, November 14, 2017 at 9:56:28 PM UTC+5:30, 
[email protected] wrote:
>
> Hi all,
>
> I'm wonder if it's possible to pass variables from playbook to role which 
> has template.
> Example:
>
> playbook.yml
> - roles:
>         - { role: monit, monit_proc: "sshd",monit_ssh_port: "25"}
>
> monit role:
>    monit/templates/sshd.conf.j2 :
>   check process sshd with pidfile {{ monit_ssh_pid }}
>   group system
>   start program "/etc/init.d/ssh start"
>   stop  program "/etc/init.d/ssh stop"
>   if failed port {{ monit_ssh_port }}  protocol ssh then restart
>   if {{ monit_restarts }} restarts within {{ monit_cycles}} cycles then 
> timeout
>
>  monit/tasks/main.yml :
>
>     - name: Add {{ monit_proc }}
>       template: 
> src=/etc/ansible/configs/monit/monit.d/{{monit_proc}}.j2.conf
>                 dest=/etc/monit/conf.d/{{monit_proc}}.conf
>       tags:
>         - monit_cfg
>
> Or maybe it's wrong approach ?
>
> Best regards,
>
> Morbious
>

-- 
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/84da674e-1525-4400-85a2-faed87e755f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to