使用动态清单时,剧本不检查所有服务器的服务状态
playbook not checking the status of service for all the servers when using dynamic inventory
- 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 个节点上都失败了,播放失败。
By default, Ansible will continue executing actions as long as there
are hosts in the batch that have not yet failed
参考:https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html
关于从可能的 226 台服务器中仅获取 64 台服务器,动态清单中是否存在任何文件管理器 file/script?请 post 详细说明。
- 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 个节点上都失败了,播放失败。
By default, Ansible will continue executing actions as long as there are hosts in the batch that have not yet failed
参考:https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html
关于从可能的 226 台服务器中仅获取 64 台服务器,动态清单中是否存在任何文件管理器 file/script?请 post 详细说明。