Gah not quite there. I use meta_end play when I calculate that a patch 
isn't relevant so that we don't spend time decomissioning a host that 
doesn't need a patch. Problem is this skips the post_tasks if the last 
server in the group isn't relevant. I tried using handlers but that results 
in 1 execution per node.

I think I might need to re-think my playbook organization and simplify. I 
could use a workflow in tower to accomplish this simpler without skipped 
tasks.


On Thursday, February 15, 2018 at 11:25:41 AM UTC-6, Michael Perzel wrote:
>
> In case someone else has this issue, for my post task I that I only want 
> to run on the last host I used the below conditional. Results in skipped 
> tasks but it does accomplish the goal. Not sure if there is a more elegant 
> way to say run on the last host.
>
> when: inventory_hostname == ansible_play_hosts[ ansible_play_hosts | 
> length - 1]
>
>
> This results in 
>
> TASK [command] 
> **************************************************************************************************************************************
> changed: [mdl-swch01] => {"changed": true, "cmd": "echo \"pre\"", "delta": 
> "0:00:00.002647", "end": "2018-02-15 11:19:37.098522", "rc": 0, "start": 
> "2018-02-15 11:19:37.095875", "stderr": "", "stderr_lines": [], "stdout": 
> "pre", "stdout_lines": ["pre"]}
>
> TASK [command] 
> **************************************************************************************************************************************
> changed: [mdl-swch01] => {"changed": true, "cmd": "echo \"task 1\"", 
> "delta": "0:00:00.003688", "end": "2018-02-15 11:19:43.144388", "rc": 0, 
> "start": "2018-02-15 11:19:43.140700", "stderr": "", "stderr_lines": [], 
> "stdout": "task 1", "stdout_lines": ["task 1"]}
>
> TASK [command] 
> **************************************************************************************************************************************
> changed: [mdl-swch01] => {"changed": true, "cmd": "echo \"task 2\"", 
> "delta": "0:00:00.002865", "end": "2018-02-15 11:19:49.189866", "rc": 0, 
> "start": "2018-02-15 11:19:49.187001", "stderr": "", "stderr_lines": [], 
> "stdout": "task 2", "stdout_lines": ["task 2"]}
>
> TASK [command] 
> **************************************************************************************************************************************
> skipping: [mdl-swch01] => {"changed": false, "skip_reason": "Conditional 
> result was False"}
>
> PLAY [Hello World Linux] 
> ****************************************************************************************************************************
>
> TASK [command] 
> **************************************************************************************************************************************
> skipping: [mdl-swch02] => {"changed": false, "skip_reason": "Conditional 
> result was False"}
>
> TASK [command] 
> **************************************************************************************************************************************
> changed: [mdl-swch02] => {"changed": true, "cmd": "echo \"task 1\"", 
> "delta": "0:00:00.002640", "end": "2018-02-15 11:19:50.853990", "rc": 0, 
> "start": "2018-02-15 11:19:50.851350", "stderr": "", "stderr_lines": [], 
> "stdout": "task 1", "stdout_lines": ["task 1"]}
>
> TASK [command] 
> **************************************************************************************************************************************
> changed: [mdl-swch02] => {"changed": true, "cmd": "echo \"task 2\"", 
> "delta": "0:00:00.002785", "end": "2018-02-15 11:19:51.261013", "rc": 0, 
> "start": "2018-02-15 11:19:51.258228", "stderr": "", "stderr_lines": [], 
> "stdout": "task 2", "stdout_lines": ["task 2"]}
>
> TASK [command] 
> **************************************************************************************************************************************
> changed: [mdl-swch02] => {"changed": true, "cmd": "echo \"post\"", 
> "delta": "0:00:00.003841", "end": "2018-02-15 11:19:51.683943", "rc": 0, 
> "start": "2018-02-15 11:19:51.680102", "stderr": "", "stderr_lines": [], 
> "stdout": "post", "stdout_lines": ["post"]}
>
>
> On Thursday, February 15, 2018 at 7:12:38 AM UTC-6, Michael Perzel wrote:
>>
>> Thanks.
>>
>> when: inventory_hostname == ansible_play_hosts[0]
>>
>> Is exactly what I need.
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/bba5a6e8-b253-45e5-a843-7f76429f83d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to