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/addd59e8-c02f-4e3e-a6a9-001878f32ce3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to