ansible - 使用动态清单时,剧本未检查所有服务器的服务状态
问题描述
- name: Check Agent Services
hosts: all
serial: 25
become: true
become_method: sudo
gather_facts: yes # speed up when we don't need to gather facts
tasks:
- name: Gathering service facts
service_facts:
register: services_state
- debug: var=services_state.ansible_facts.services["besclient.service"].state
- debug: var=services_state.ansible_facts.services["taniumclient.service"].state
- debug: var=services_state.ansible_facts.services["filebeat.service"].state
- debug: var=services_state.ansible_facts.services["ds_agent.service"].state
- debug: var=services_state.ansible_facts.services["splunk.service"].state
- debug: var=hostvars[inventory_hostname]['ansible_default_ipv4']['address']
- name: Gather Info
become: false
local_action: shell echo "{{ services_state.ansible_facts.services["besclient.service"].state | default('MISSING') }} {{ services_state.ansible_facts.services["taniumclient.service"].state | default('MISSING') }} {{ services_state.ansible_facts.services["filebeat.service"].state | default('MISSING') }} {{ services_state.ansible_facts.services["ds_agent.service"].state | default('MISSING') }} {{ services_state.ansible_facts.services["splunk.service"].state | default('MISSING') }} {{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }} {{ hostvars[inventory_hostname]['ansible_fqdn'] }}" >> /tmp/result
ansible-playbook service_status.yaml -i ../dynamic_inventory/US/ -u xxxxx --ask-pass --ask-become-pass
我正在使用这个剧本来检查服务的状态,使用动态库存。总共有 700 多台服务器,其中 226 台服务器应该响应这个剧本。
如果我在这 226 台服务器上使用清单文件,结果将复制到 /tmp/result。
ansible-playbook service_status.yaml -i /tmp/inventory -u xxxxx --ask-pass --ask-become-pass
但是当我使用动态库存时,我会从少数服务器(64)处获得响应。我需要在配置中启用任何东西吗?
TASK [Gathering Facts] *************************************************************************************************************************************************************************
fatal: [172.15.17.150]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: no such identity: /home/xxxx/.ssh/id_ed25519: No such file or directory\r\nPermission denied (publickey,password).", "unreachable": true}
fatal: [172.15.176.155]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: no such identity: /home/xxxx/.ssh/id_ed25519: No such file or directory\r\nPermission denied (password,publickey,keyboard-interactive).", "unreachable": true}
fatal: [172.15.162.138]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.162.138 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.163.143]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.163.143 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.17.146]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.17.146 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.17.135]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.17.135 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.177.134]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.177.134 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.177.149]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.177.149 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.177.151]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.177.151 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.177.152]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.177.152 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.177.164]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.177.164 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.177.181]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.177.181 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.177.189]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.177.189 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.177.205]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.177.205 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.177.199]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.177.199 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.177.249]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.177.249 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.178.139]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.178.139 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.178.168]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.178.168 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.179.139]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.179.139 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.179.166]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.179.166 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.179.142]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.179.142 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.179.190]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.179.190 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.179.222]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.179.222 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.18.133]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.18.133 port 22: Connection timed out", "unreachable": true}
fatal: [172.15.18.157]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 172.15.18.157 port 22: Connection timed out", "unreachable": true}
解决方案
添加到上述问题:我可以看到 playbook 在 25+ 服务器故障后停止
由于您在 playbook 中添加了“serial: 25”,因此 ansible 将以 25 个批次在主机上执行。由于您的第一批本身在所有 25 个节点上都失败,因此播放失败。
默认情况下,只要批处理中有主机尚未失败,Ansible 就会继续执行操作
参考:https ://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html
关于从可能的 226 台服务器中仅获得 64 台服务器,动态库存文件/脚本中是否存在任何文件管理器?请张贴有关的详细信息。
推荐阅读
- python-3.x - 如何在 Python 中使用 XSD 验证 XML
- sql - 如果结果为空,则显示一列我在哪里输入的内容
- c# - 使用 2.1 版的 Service Fabric .net 核心远程处理
- react-native - 如何同时处理视图和按钮的点击?
- android - 我将leakcanary与2.0-beta-3版本集成,应用程序闪烁
- go - 如何修改字符串中的特定字符
- python-3.x - 在 Cartopy 中将 set_aspect 设置为相等后,get_extent 不返回更新的范围
- symfony - 如何在 Symfony 命令中获取指定通道的记录器?
- python - Python中的“赋值前引用的局部变量”
- python - tensorflow TFRecords 无法解析序列化示例