如何解决Ansible事实是条件
下面是剧本
---
- name: stop agent process
shell: "ps -ef | grep -v grep | grep -w {{ MONGODB_AGENT_PROCESS }} | awk '{print $2}'"
register: running_agent_processes
- name: stop mongod process
shell: "ps -ef | grep -v grep | grep -w {{ MONGODB_SERVER_PROCESS }} | awk '{print $2}'"
register: running_mongod_processes
- name: combine processes
set_fact:
all_processes: "{{ running_agent_processes.stdout_lines + running_mongod_processes.stdout_lines }}"
- name: Kill all processes
shell: "kill {{ item }}"
with_items: "{{ all_processes }}"
when: ansible_facts[ansible_hostname] != primary
- wait_for:
path: "/proc/{{ item }}/status"
state: absent
with_items: "{{ all_processes }}"
ignore_errors: yes
register: killed_processes
when: ansible_facts[ansible_hostname] != primary
- name: Force kill stuck processes
shell: "kill -9 {{ item }}"
with_items: "{{ killed_processes.results | select('failed') | map(attribute='item') | list }}"
when: ansible_facts[ansible_hostname] != primary
我存储了一个称为“ primary”的事实,该事实存储了剧本中上一步中的mongodb副本集的primary。
我只想将ansible_facts[ansible_hostname]
与我的primary
事实进行比较。如果它们不相等,我想杀死进程。
我得到的错误如下:
致命:[lpdkubpoc01d.phx.aexp.com]:失败! => {“ msg”:“ 条件检查“ ansible_facts [ansible_hostname]!=主要”失败。 错误是:评估条件错误 (ansible_facts [ansible_hostname]!= primary):“ ansible_facts”为 未定义\ n \ n错误似乎出在 '/idn/home/sanupin/stop-enterprise-mongodb/tasks/stopAutomationAgent.yml': 第11行第3列,但\ n可能不在文件的其他位置,具体取决于 确切的语法问题。\ n \ n出现问题的行似乎是:\ n \ n
all_processes:“ {{running_agent_processes.stdout_lines + running_mongod_processes.stdout_lines}}“ \ n-名称:全部杀死 进程\ n ^这里\ n“}致命:[lpdkubpoc01c.phx.aexp.com]:失败!=> {“ msg”:“条件检查'ansible_facts [ansible_hostname]!= 主要”失败。错误是:评估条件错误 (ansible_facts [ansible_hostname]!= primary):“ ansible_facts”为 未定义\ n \ n错误似乎出在 '/idn/home/sanupin/stop-enterprise-mongodb/tasks/stopAutomationAgent.yml': 第11行第3列,但\ n可能不在文件的其他位置,具体取决于 确切的语法问题。\ n \ n出现问题的行似乎是:\ n \ n
all_processes:“ {{running_agent_processes.stdout_lines + running_mongod_processes.stdout_lines}}“ \ n-名称:全部杀死 进程\ n ^这里\ n“}致命:[lpdkubpoc01e.phx.aexp.com]:失败!=> {“ msg”:“条件检查'ansible_facts [ansible_hostname]!= 主要”失败。错误是:评估条件错误 (ansible_facts [ansible_hostname]!= primary):“ ansible_facts”为 未定义\ n \ n错误似乎出在 '/idn/home/sanupin/stop-enterprise-mongodb/tasks/stopAutomationAgent.yml': 第11行第3列,但\ n可能不在文件的其他位置,具体取决于 确切的语法问题。\ n \ n出现问题的行似乎是:\ n \ n
all_processes:“ {{running_agent_processes.stdout_lines + running_mongod_processes.stdout_lines}}“ \ n-名称:全部杀死 进程\ n ^这里\ n“}
有人可以帮我比较ansible_fact与set_fact事实吗?
解决方法
您可以比较直接使用的可疑事实,而无需事先写ansible_facts
。只需用作when: ansible_hostname != primary
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。