1

I have a simple-ish ansible playbook which deploys some software on remote hosts. When I run it with -vvv I see hundreds of the following messages:

[2020-04-07 17:22:29] <54.234.19.60> ESTABLISH SSH CONNECTION FOR USER: centos

Each of those will take around half a second for a total of several minutes per deployment.

How do I make Ansible open a single SSH connection per host when work is started, do all of its operations through this connection, close it when all work is done?

alamar
  • 18,729
  • 4
  • 64
  • 97
  • This sounds like a strong candidate for Mitogen: https://mitogen.networkgenomics.com/ansible_detailed.html – Matthew Schuchard Apr 07 '20 at 14:51
  • @MattSchuchard Mitogen seems to work OK, but run time difference is modest. Still, maybe it will make sense to add an answer? – alamar Apr 07 '20 at 16:49

1 Answers1

3

Try adding:

[ssh_connection]
pipelining = True

in ansible.cfg

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ssh_connection.html#parameter-pipelining

Additionally you can try adding ControlPersist:

[ssh_connection]
pipelining = True
control_path = /tmp/ansible-ssh-%%h-%%p-%%r
#or simply:
#control_path = /tmp

to the same section in the cfg file.

Andreas
  • 5
  • 1
  • 4
Ron
  • 5,900
  • 2
  • 20
  • 30
  • Unfortunately, it did not help, I still see individual SSH commands in the terminal all the time :( – alamar Apr 07 '20 at 15:18
  • But after all changes it seems to pass faster indeed. I have also increased `connect_timeout = 120` – alamar Apr 07 '20 at 16:30
  • 1
    Well there might be many other factors, like connection speed, network, CPU/Memory of the executing machine.. it's connectivity.. other configs.. :) – Ron Apr 07 '20 at 17:02