Template Input Variable Not Passed Correctly to Ansible Role in Job

Hi,

I’m having trouble passing a user-defined template input (crowdstrike) from Foreman into an Ansible role using an Ansible Job Template. Here’s what I have configured:

Job Template YAML **


  • hosts: all
    become: true
    gather_facts: true
    roles:
    • role: workgroup_local_liunx_rke_k8s

Inside the role workgroup_local_liunx_rke_k8s/tasks/main.yml:

  • name: Install CrowdStrike if enabled
    copy:
    src: falcon.rpm
    dest: /tmp/falcon.rpm
    when: howtopasshere == “yes”

If the user selects yes, then the variable crowdstrike should be “yes” and the task should run.

If no, then it should be skipped.

I am trying to understand how to pass to the ansible.
Any help or working example will be appreciated.

Thank you!

Something like this should to the trick

# job template yml
- hosts: all
  roles:
    - role: workgroup_local_linux_rke_k8s
      vars:
        howtopasshere: "<%= input('crowdstrike') %>"

The input should then be available as howtopasshere variable inside the role.

Note I’ve dropped gather_fact: true which should be the default and become: true. If you need privilege escalation, it is better to leave it to foreman rather than hardcoding it into the job template content.

Also, you have some typos in the screenshot, double check that the input name and the value you pass into the input macro inside the job template actually match.

Hi,
Sory for the late respond.
It works.
Thanks :slight_smile: