patternMinor
Questions about Ansible connection to remote hosts
Viewed 0 times
hostsquestionsaboutremoteansibleconnection
Problem
I want to ask some questions about working of Ansible.
1 - Which shell Ansible uses when logging to remote host ?
https://askubuntu.com/questions/937354/track-logins-made-via-non-interactive-shells/937716?noredirect=1#comment1486867_937716
2 - If I have 10 tasks in a playbook, then ansible makes connection 10 times to remote host OR uses a single connection to perform all these 10 tasks ?
3 - If I am running 10 tasks on 2 hosts,
It will do first task on host 1 and then on host 2
then second task on host 1 and then on host 2,
..
. so on,
.
So, here also the connection persists to both the hosts?
OR
does it firstly connect to host 1, runs task 1 and then disconnects AND then connects to host 2, runs task 1 and then disconnects ?
1 - Which shell Ansible uses when logging to remote host ?
https://askubuntu.com/questions/937354/track-logins-made-via-non-interactive-shells/937716?noredirect=1#comment1486867_937716
2 - If I have 10 tasks in a playbook, then ansible makes connection 10 times to remote host OR uses a single connection to perform all these 10 tasks ?
3 - If I am running 10 tasks on 2 hosts,
It will do first task on host 1 and then on host 2
then second task on host 1 and then on host 2,
..
. so on,
.
So, here also the connection persists to both the hosts?
OR
does it firstly connect to host 1, runs task 1 and then disconnects AND then connects to host 2, runs task 1 and then disconnects ?
Solution
Can't answer 1 (I always thought it just uses the default /bin/sh unless specified otherwise?).
-
It will make the connection more than 10 times. A single task will typically have an SCP or SFTP connection to copy the taskfile that'll get remotely executed, then another connection to trigger the script. You can monitor this happening by running your playbook with -vvv, such as:
3rd-level verbosity shows all connections to client.
-
By default, Ansible will execute tasks concurrently on all hosts up to the max configured number of forks. So, it'll run task 1 on both hosts, then it'll run task 2 on both hosts, etc. Forks are defined in ansible.cfg, and default to 5. Change this variable to a higher number or comment it out:
Optionally, you can also do a rolling batch when running playbooks by specifying the
Say you're running a playbook against 5 hosts, and have the serial option set. With serial = 1, it will run the full playbook 1 host at a time. With serial = 2, it will run hosts 1 & 2, then hosts 2 & 3, then host 5. Example:
More reading:
Serial (rolling) playbook runs:
Forks:
Hope this helps.
-
It will make the connection more than 10 times. A single task will typically have an SCP or SFTP connection to copy the taskfile that'll get remotely executed, then another connection to trigger the script. You can monitor this happening by running your playbook with -vvv, such as:
ansible-playbook deploy_app.yml -u maplebird -vvv3rd-level verbosity shows all connections to client.
-
By default, Ansible will execute tasks concurrently on all hosts up to the max configured number of forks. So, it'll run task 1 on both hosts, then it'll run task 2 on both hosts, etc. Forks are defined in ansible.cfg, and default to 5. Change this variable to a higher number or comment it out:
forks = 5Optionally, you can also do a rolling batch when running playbooks by specifying the
serial option in the playbook. This will only concurrently execute tasks for however many hosts you've defined.Say you're running a playbook against 5 hosts, and have the serial option set. With serial = 1, it will run the full playbook 1 host at a time. With serial = 2, it will run hosts 1 & 2, then hosts 2 & 3, then host 5. Example:
name: deploy to all webservers
hosts: webservers
serial: 2
roles:
- deploy_applicationMore reading:
Serial (rolling) playbook runs:
- http://docs.ansible.com/ansible/latest/playbooks_delegation.html#rolling-update-batch-size
Forks:
- http://docs.ansible.com/ansible/latest/intro_configuration.html#forks
Hope this helps.
Code Snippets
ansible-playbook deploy_app.yml -u maplebird -vvvname: deploy to all webservers
hosts: webservers
serial: 2
roles:
- deploy_applicationContext
StackExchange DevOps Q#1577, answer score: 7
Revisions (0)
No revisions yet.