我有以下剧本。如果我使用--tags“ decommision”运行,则仅触发2个正确的任务。但是,当我使用--tags“ deliver”运行剧本时,无论其标签是否为“ decommission”,最后的任务仍在运行。我似乎不知道。我的缩进也很好。
tasks:
- name: Change PS 1
command: sed -i 's/PS1=\"\[\\u\@\\h\ \\W\]/PS1=\"\[\\u\@\\H\ \\W\]/g' /etc/bashrc
tags: deliver, update
- name: Update Info In CMDB
uri:
url: "update url"
method: POST
body: {"ip_list": ["{{ ansible_host }}"]}
body_format: json
tags: deliver, update
- name: Remove Old Targets
uri:
url: "remove url"
method: POST
body: {"job_name": "{{ jobname }}", "host_list": ["{{ ansible_host }}"]}
body_format: json
tags: deliver, decommision, update
- name: Associate Host With Prometheus
uri:
url: "prometheus url"
method: POST
body: {"ip_list": [ "{{ ansible_host }}" ]}
body_format: json
tags: deliver
- name: Register monitoring job
uri:
url: "register url"
method: POST
body: {"host_list": ["{{ ansible_host }}"]}
body_format: json
tags: deliver, update_hostname
- name: Remove Association Host With Prometheus
uri:
url: "remove url"
method: POST
body: {"ip_list": [ "{{ ansible_host }}" ]}
body_format: json
tags: decommision
答案 0 :(得分:0)
按预期工作
shell> cat pb.yml
- hosts: localhost
gather_facts: false
tasks:
- debug:
msg: Change PS 1
tags: deliver, update
- debug:
msg: Update Info In CMDB
tags: deliver, update
- debug:
msg: Remove Old Targets
tags: deliver, decommision, update
- debug:
msg: Associate Host With Prometheus
tags: deliver
- debug:
msg: Register monitoring job
tags: deliver, update_hostname
- debug:
msg: Remove Association Host With Prometheus
tags: decommision
给予(删节)
shell> ansible-playbook pb.yml --tags "deliver" | grep msg\:
msg: Change PS 1
msg: Update Info In CMDB
msg: Remove Old Targets
msg: Associate Host With Prometheus
msg: Register monitoring job