0

I implemented a playbook to iterate over 10 hosts. From those 10 hosts, host_2 and host_8 are slow. I used for this setup a batch size of 2. My expected outcome is when the playbook will start with host_1 and host_2 as soon as it finish with host_1 (which is faster), it will grab a host from the next batch instead of waiting for both hosts to finish in order to start with the next batch. Unfortunately using the playbook with host_pinned strategy which is supposed to work as my expectation, the outcome was the same as free strategy where the next batch will start only when both hosts are finished from the current batch. The outcome is bellow:

 PLAY [all] **************************************************************************************************************************************************************************************************************************************************************************

    TASK [stop : stop for specific hosts] ***********************************************************************************************************************************************************************************************************************************************

    TASK [stop : stop for specific hosts] ***********************************************************************************************************************************************************************************************************************************************
    skipping: [host_1]

    TASK [stop : debug] *****************************************************************************************************************************************************************************************************************************************************************
    skipping: [host_1]

    TASK [stop : stop for other hosts] **************************************************************************************************************************************************************************************************************************************************
    changed: [host_1 -> localhost]

    TASK [stop : debug] *****************************************************************************************************************************************************************************************************************************************************************
    ok: [host_1] => {
        "msg": "stop host_1 10:57:16.373188889"
    }

    TASK [update : update] **************************************************************************************************************************************************************************************************************************************************************
    changed: [host_1 -> localhost]

    TASK [update : debug] ***************************************************************************************************************************************************************************************************************************************************************
    ok: [host_1] => {
        "msg": "updating host_1 10:57:21.788484077\nupdated host_1 10:57:23.790958603"
    }

    TASK [start : start] ****************************************************************************************************************************************************************************************************************************************************************
    changed: [host_1 -> localhost]

    TASK [start : debug] ****************************************************************************************************************************************************************************************************************************************************************
    ok: [host_1] => {
        "msg": "start host_1 10:57:24.185053675"
    }

    TASK [start : debug] ****************************************************************************************************************************************************************************************************************************************************************
    changed: [host_2 -> localhost]

    TASK [stop : debug] *****************************************************************************************************************************************************************************************************************************************************************
    ok: [host_2] => {
        "msg": "stop host_2 10:57:16.415522282"
    }

    TASK [stop : stop for other hosts] **************************************************************************************************************************************************************************************************************************************************
    skipping: [host_2]

    TASK [stop : debug] *****************************************************************************************************************************************************************************************************************************************************************
    skipping: [host_2]

    TASK [update : update] **************************************************************************************************************************************************************************************************************************************************************
    changed: [host_2 -> localhost]

    TASK [update : debug] ***************************************************************************************************************************************************************************************************************************************************************
    ok: [host_2] => {
        "msg": "updating host_2 10:58:17.368744495\nupdated host_2 10:58:19.372907064"
    }

    TASK [start : start] ****************************************************************************************************************************************************************************************************************************************************************
    changed: [host_2 -> localhost]

    TASK [start : debug] ****************************************************************************************************************************************************************************************************************************************************************
    ok: [host_2] => {
        "msg": "start host_2 10:58:19.903162652"
    }

    PLAY [all] **************************************************************************************************************************************************************************************************************************************************************************

    TASK [stop : stop for specific hosts] ***********************************************************************************************************************************************************************************************************************************************

    TASK [stop : stop for specific hosts] ***********************************************************************************************************************************************************************************************************************************************
    skipping: [host_3]

    TASK [stop : debug] *****************************************************************************************************************************************************************************************************************************************************************

    TASK [stop : debug] *****************************************************************************************************************************************************************************************************************************************************************
    skipping: [host_4]

    TASK [stop : debug] *****************************************************************************************************************************************************************************************************************************************************************
    skipping: [host_3]

    TASK [stop : stop for other hosts] **************************************************************************************************************************************************************************************************************************************************

    TASK [stop : stop for other hosts] **************************************************************************************************************************************************************************************************************************************************
    skipping: [host_4]

    TASK [stop : stop for other hosts] **************************************************************************************************************************************************************************************************************************************************
    changed: [host_3 -> localhost]

    TASK [stop : debug] *****************************************************************************************************************************************************************************************************************************************************************
    ok: [host_3] => {
        "msg": "stop host_3 10:58:21.214160633"
    }

    TASK [update : update] **************************************************************************************************************************************************************************************************************************************************************

    TASK [update : update] **************************************************************************************************************************************************************************************************************************************************************
    changed: [host_4 -> localhost]

    TASK [stop : debug] *****************************************************************************************************************************************************************************************************************************************************************
    ok: [host_4] => {
        "msg": "stop host_4 10:58:21.329958767"
    }

    TASK [update : update] **************************************************************************************************************************************************************************************************************************************************************
    changed: [host_3 -> localhost]

    TASK [update : debug] ***************************************************************************************************************************************************************************************************************************************************************
    ok: [host_3] => {
        "msg": "updating host_3 10:58:26.831347906\nupdated host_3 10:58:28.833336983"
    }

    TASK [start : start] ****************************************************************************************************************************************************************************************************************************************************************

    TASK [start : start] ****************************************************************************************************************************************************************************************************************************************************************
    changed: [host_4 -> localhost]

    TASK [update : debug] ***************************************************************************************************************************************************************************************************************************************************************
    ok: [host_4] => {
        "msg": "updating host_4 10:58:26.953679789\nupdated host_4 10:58:28.970638599"
    }

    TASK [start : start] ****************************************************************************************************************************************************************************************************************************************************************
    changed: [host_3 -> localhost]

    TASK [start : debug] ****************************************************************************************************************************************************************************************************************************************************************
    ok: [host_3] => {
        "msg": "start host_3 10:58:29.662201166"
    }

    TASK [start : debug] ****************************************************************************************************************************************************************************************************************************************************************
    changed: [host_4 -> localhost]

    TASK [start : debug] ****************************************************************************************************************************************************************************************************************************************************************
    ok: [host_4] => {
        "msg": "start host_4 10:58:29.801761229"
    }

Did I misunderstood the host_pinned strategy? Can you give me some guidance in how to implement my approach using Ansible?

raeX
  • 3,197
  • 2
  • 14
  • 21

1 Answers1

0

The problem you are having is due to your use of batching rather than your strategy plugin. The ansible documentation specifically states that it will not move on until the entire batch is complete (See below). There are other ways to speed things up though. You could consider using ssh pipelining (requires disabling requiretty in /etc/suoders) or even mitogen. Here's an article on the subject: https://www.toptechskills.com/ansible-tutorials-courses/speed-up-ansible-playbooks-pipelining-mitogen/

https://docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html#rolling-update-batch-size

In the above example, if we had 4 hosts in the group ‘webservers’, 2 would complete the play completely before moving on to the next 2 hosts:

Dustin
  • 53
  • 6
  • thank you for your replay. The only way to speed up the playbook execution is to use plugins then? for using pipelining, I believe disabling requiretty is no longer required since ansible 2.6 or sth. Is this correct ? – raeX Nov 18 '19 at 09:51
  • 1
    Well I wouldn't say it is the only way, but it is the first and most obvious step, especially in your case since you have some hosts that are so much slower than others. Also, per the 2.9 documentation pipelining still requires disabling requiretty. I can't recommend mitogen enough really. It will make a huge difference in the speed of your plays and greatly reduce both network and controller load without having to make any changes on your client devices. It's very easy to install. – Dustin Nov 19 '19 at 15:23