Search code examples
ansibleyamlansible-templateansible-tower

Can ansible variables be used to declare hosts in a playbook?


I have a playbook in the format below:

---
- hosts: myIP
  tasks:
  - name: Install a yum package in Ansible example
    yum:
      name: ThePackageIWantToInstall
      state: present

where myIP and ThePackageIWantToInstall are variables.

When the job template runs, I would like the user in the extra variables popup to be able to go with:

myIP = 192.168.1.1
ThePackageIWantToInstall = nano

As the documentation doesn't provide an example of supplying a variable via a job template, is this possible?


Solution

  • Yes.

    - name: Do The Thing
      hosts: "{{ foo }}"
      roles:
       - "{{ role }}"
    

    Need mustaches and quotes.


    to run from popup

    (I don't use this, but it was suggested as an edit, thanks...)

    foo: value