Webhook会触发AWX作业,我想根据服务在特定主机上运行部署,因为它们在不同的服务器上运行。我需要知道哪个服务器使用该服务将其设置为var,以便在以下播放中可用作主机。
我在vars.yaml中的变量如下所示:
staging_hosts:
server1: ['service1', 'service2', 'service3']
server2: ['service4', 'service5', 'service6']
server3: ['service7', 'service8', 'service9']
剧本:
- name: write deployment hosts
hosts: localhost
vars:
deployment_hosts: absent
vars_files:
- ./group_vars/vars.yaml
tasks:
- set_fact:
modified_repos: (small regex filter to find modified repository)
- set_fact:
deployment_hosts: "{{ item }}"
when: '{{ modified_repos }} in {{ item }}'
with_list:
- "{{ staging_hosts }}"
- name: connect to Cluster
hosts: "{{ hostvars['localhost']['deployment_hosts'] }}"
我该如何处理此警告和错误?
[WARNING]: conditional statements should not include jinja2 templating
delimiters such as {{ }} or {% %}. Found: {{ modified_repos }} in {{ item }}
fatal: [localhost]: FAILED! => {"msg": "The conditional check '{{ modified_repos }} in {{ item }}' failed. True {% else %} False {% endif %}): unhashable type: 'list'
哦,我忘了提。重要的是,如果修改后的回购包括例如service1和service4,那么Deployment_hosts也可以包含两个主机。
问:“如果修改后的回购包括service1和service4,则deployment_hosts也可以包含两个主机。”
答:使用相交滤镜。例如,剧本
- hosts: localhost
vars:
staging_hosts:
server1: ['service1', 'service2', 'service3']
server2: ['service4', 'service5', 'service6']
server3: ['service7', 'service8', 'service9']
modified_repos: ['service1', 'service4']
tasks:
- set_fact:
deployment_hosts: "{{ deployment_hosts|default([]) + [item.key] }}"
loop: "{{ staging_hosts|dict2items }}"
when: modified_repos|intersect(item.value)|length > 0
- debug:
var: deployment_hosts
给
deployment_hosts:
- server1
- server2
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句