我正在使用Ansible来部署可能分发或不分发服务的环境.我想条件性地包括基于我传递给ansible-playbook的论据的剧本.
create_server.yml
--- - include: launch_ec2_instance.yml - include install_postgres.yml when {{db}} == "Y" - include install_redis.yml when {{redis}} == "Y"
这是我如何调用create_server.yml
ansible-playbook create_server.yml -i local --extra-vars "db=Y redis=N"
有可能这样做,如果是这样,怎么样?
是.这是可能的.您在when语句中缺少冒号(:).
--- - include: launch_ec2_instance.yml - include install_postgres.yml when: {{ db }} == "Y" - include install_redis.yml when: {{ redis }} == "Y"
您还可以省略大括号({{}}):
--- - include: launch_ec2_instance.yml - include install_postgres.yml when: db == "Y" - include install_redis.yml when: redis == "Y"