Ansible-playbook使用变量、标记和限制调用另一个playbook
我有一本蓝绿色的剧本。它依赖于某些变量来确定应用底层角色的主机。以下是一个示例的角色之一:Ansible-playbook使用变量、标记和限制调用另一个playbook,ansible,ansible-playbook,ansible-2.x,Ansible,Ansible Playbook,Ansible 2.x,我有一本蓝绿色的剧本。它依赖于某些变量来确定应用底层角色的主机。以下是一个示例的角色之一: - name: Remove current server from load balancer hosts: 'tag_Name_{{server_name}}_production' remote_user: ec2-user sudo: true roles: - remove-load-balancer 我可以用指定的限制和标签来调用这个剧本,它工作得非常好——但只适用于
- name: Remove current server from load balancer
hosts: 'tag_Name_{{server_name}}_production'
remote_user: ec2-user
sudo: true
roles:
- remove-load-balancer
我可以用指定的限制和标签来调用这个剧本,它工作得非常好——但只适用于一种类型的服务器。例如,此命令将以蓝绿色部署我们的服务服务器:
ansible-playbook blue.green.yml -i ec2.py -l tag_Name_services_production,tag_Name_services_production_old --skip-tags=restart,stop -e server_name=services -e core_repo=~/core
我想写一个蓝绿色的主剧本,它基本上运行几个剧本——首先是api服务器,然后是服务服务器。我尝试过使用include,但似乎无法正确使用语法-ansible要么抱怨我的任务没有做任何事情,要么抱怨语法不正确:
理想情况下,我可以这样称呼:
ansible-playbook blue.green.yml -i ec2.py -e core_repo=~/core
有人成功地做到了吗?如果是-我如何才能做到这一点?这对您的案例有效吗
- name: Blue green deploy to all production boxes.
hosts: [tag_Name_api_production, tag_Name_api_production_old]
tasks:
- include: blue.green.single.yml
vars:
- server_name: api
skip-tags:
- restart
- stop
- name: Blue green deploy to all production boxes.
hosts: [tag_Name_services_production, tag_Name_services_production_old]
tasks:
- include: blue.green.single.yml
vars:
- server_name: services
skip-tags:
- restart
- stop
我如何使用更新版本(如2.4)来实现这一点?
- name: Blue green deploy to all production boxes.
hosts: [tag_Name_api_production, tag_Name_api_production_old]
tasks:
- include: blue.green.single.yml
vars:
- server_name: api
skip-tags:
- restart
- stop
- name: Blue green deploy to all production boxes.
hosts: [tag_Name_services_production, tag_Name_services_production_old]
tasks:
- include: blue.green.single.yml
vars:
- server_name: services
skip-tags:
- restart
- stop