0

Standard way of defining an Ansible playbook with roles is:

--- 
- hosts: webservers 
  roles:
    - common 
    - webservers

I would like to pass a single command line variable for the Ansible role. I mean to say there should be a single Ansible role which would be a variable and I should be able to pass the choice of role (common or webserver) from outside.

Please let me know if and how we can achieve this:

roles:
  - {{ choice }}
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
Balajee Venkatesh
  • 1,041
  • 2
  • 18
  • 39

1 Answers1

2

Use include_role in play.yml

- hosts: webservers
  tasks:
    - include_role:
        name: "{{ choice }}"

and run it

# ansible-playbook -e "choice=common" play.yml
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63