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 }}
答案 0 :(得分:1)
在 play.yml
中使用include_role- hosts: webservers
tasks:
- include_role:
name: "{{ choice }}"
并运行它
# ansible-playbook -e "choice=common" play.yml