如何解决使用动态清单时,剧本不检查所有服务器的服务状态
- 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}
解决方法
添加到上述问题中:我看到该剧本在25台以上服务器故障后停止了播放
由于您在剧本中添加了“序列号:25”,因此ansible将在25个主机中的主机上执行。由于第一批本身在所有25个节点上均失败,因此播放失败。
默认情况下,只要有,Ansible就会继续执行操作 批次中尚未失败的主机
引用:https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html
关于仅从可能的226个服务器中删除64个服务器,动态清单文件/脚本中是否存在文件管理器?请发布有关的详细信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。