Multiple simultaneous requests to same host for same task give "Data could not be sent to remote host IP. Make sure this host can be reached over ssh

Viewed 108

Scenario

I run the following tasks in two terminals at the same time

  • first one succeeds
  • second one gives above error

So we are getting the above error while running the ansible-playbook for multiple sessions at the same time

Data could not be sent to remote host [internal ip]. Make sure this host can be reached over ssh

The piece of code being executed by task which fails is

- name: run docker container
  docker_container:
    name: "{{ container_name }}"
    image: "organization/{{ app_name }}:{{ docker_image_version }}"
#    command: "{{ adhoc_command }}"
    command: "/bin/sh /data/run-command.sh"
    state: started
    recreate: yes
    capabilities:
      - sys_time
    cap_drop:
      - all
    privileged: true
    cleanup: true
    detach: false
    network_mode: host
    env_file: "{{ adhock_data_path }}/{{ app_name }}/{{ md5suffix }}/.env"
    volumes:
      - "{{ adhock_data_path }}/{{ app_name }}/{{ md5suffix }}:/data:rw"

I suspect it is happening as we are trying to do some heavy tasks in the container at the same time.
I was thinking if there was some solution to delay the connection as well with something like the following

  wait_for_connection:
    delay: 30
    timeout: 300

But we have the same issue when both the tasks are being executed simultaneously. Any help would be appreciated.

If required, I can provide additional information as well.

1 Answers

Try updating your ansible.cfg with the value retries = 5 which will allow your playbook to retry connecting to the host 5 times with retry delay of 1s, 2s, 4s and etc. This will be more explanatory on your ansible.cfg file itself. Check once.

Related