Search code examples
ansibleansible-inventory

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

I am using this playbook to check the status of the service, using dynamic inventory. Total 700+ servers will be there,out of that 226 server should respond to this playbook.

If I am using an inventory file with this 226 servers, result is copying to /tmp/result.

ansible-playbook service_status.yaml -i /tmp/inventory -u xxxxx --ask-pass --ask-become-pass

But when I am using dynamic inventory I am getting response from few servers(64). Do I need to enable anything in configuration?

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}

Solution

  • Adding to the above issue: I can see that playbook stopped after 25+ servers failure

    Since you have added "serial: 25" in you playbook, ansible will execute on hosts in a batch of 25. Since your first batch itself is failing on ALL 25 nodes, play is failed.

    By default, Ansible will continue executing actions as long as there are hosts in the batch that have not yet failed

    Refer : https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html

    About getting only 64 servers out of possible 226, is there any filers present in dynamic inventory file/script? Please post details about that.