Skip to content

Instantly share code, notes, and snippets.

@ajalab
Last active January 12, 2021 14:01
Show Gist options
  • Save ajalab/254a1e866b5d92ef1815650414a13c81 to your computer and use it in GitHub Desktop.
Save ajalab/254a1e866b5d92ef1815650414a13c81 to your computer and use it in GitHub Desktop.
[foo]
foo1 fail=False
foo2 fail=True
foo3 fail=False
PLAY [all] *********************************************************************
TASK [Print ansible_play_batch (before failure)] *******************************
ok: [foo1] => {
"ansible_play_batch": [
"foo1",
"foo2"
]
}
ok: [foo2] => {
"ansible_play_batch": [
"foo1",
"foo2"
]
}
TASK [Print ansible_play_hosts (before failure)] *******************************
ok: [foo1] => {
"ansible_play_hosts": [
"foo1",
"foo2",
"foo3"
]
}
ok: [foo2] => {
"ansible_play_hosts": [
"foo1",
"foo2",
"foo3"
]
}
TASK [Print ansible_play_hosts_all (before failure)] ***************************
ok: [foo1] => {
"ansible_play_hosts_all": [
"foo1",
"foo2",
"foo3"
]
}
ok: [foo2] => {
"ansible_play_hosts_all": [
"foo1",
"foo2",
"foo3"
]
}
TASK [Simulate failure] ********************************************************
skipping: [foo1]
fatal: [foo2]: FAILED! => {"changed": false, "msg": "fail!"}
TASK [Print ansible_play_batch (after failure)] ********************************
ok: [foo1] => {
"ansible_play_batch": [
"foo1"
]
}
TASK [Print ansible_play_hosts (after failure)] ********************************
ok: [foo1] => {
"ansible_play_hosts": [
"foo1",
"foo3"
]
}
TASK [Print ansible_play_hosts_all (after failure)] ****************************
ok: [foo1] => {
"ansible_play_hosts_all": [
"foo1",
"foo2",
"foo3"
]
}
PLAY [all] *********************************************************************
TASK [Print ansible_play_batch (before failure)] *******************************
ok: [foo3] => {
"ansible_play_batch": [
"foo3"
]
}
TASK [Print ansible_play_hosts (before failure)] *******************************
ok: [foo3] => {
"ansible_play_hosts": [
"foo1",
"foo3"
]
}
TASK [Print ansible_play_hosts_all (before failure)] ***************************
ok: [foo3] => {
"ansible_play_hosts_all": [
"foo1",
"foo2",
"foo3"
]
}
TASK [Simulate failure] ********************************************************
skipping: [foo3]
TASK [Print ansible_play_batch (after failure)] ********************************
ok: [foo3] => {
"ansible_play_batch": [
"foo3"
]
}
TASK [Print ansible_play_hosts (after failure)] ********************************
ok: [foo3] => {
"ansible_play_hosts": [
"foo1",
"foo3"
]
}
TASK [Print ansible_play_hosts_all (after failure)] ****************************
ok: [foo3] => {
"ansible_play_hosts_all": [
"foo1",
"foo2",
"foo3"
]
}
PLAY RECAP *********************************************************************
foo1 : ok=6 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
foo2 : ok=3 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
foo3 : ok=6 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
- hosts: all
gather_facts: no
serial: 2
tasks:
- name: Print ansible_play_batch (before failure)
debug:
var: ansible_play_batch
- name: Print ansible_play_hosts (before failure)
debug:
var: ansible_play_hosts
- name: Print ansible_play_hosts_all (before failure)
debug:
var: ansible_play_hosts_all
- name: Simulate failure
fail:
msg: "fail!"
when: fail
- name: Print ansible_play_batch (after failure)
debug:
var: ansible_play_batch
- name: Print ansible_play_hosts (after failure)
debug:
var: ansible_play_hosts
- name: Print ansible_play_hosts_all (after failure)
debug:
var: ansible_play_hosts_all
PLAY [all] *********************************************************************
TASK [Print ansible_play_batch (before getting unreachable)] *******************
ok: [foo1] => {
"ansible_play_batch": [
"foo1",
"foo2"
]
}
ok: [foo2] => {
"ansible_play_batch": [
"foo1",
"foo2"
]
}
TASK [Print ansible_play_hosts (before getting unreachable)] *******************
ok: [foo1] => {
"ansible_play_hosts": [
"foo1",
"foo2",
"foo3"
]
}
ok: [foo2] => {
"ansible_play_hosts": [
"foo1",
"foo2",
"foo3"
]
}
TASK [Print ansible_play_hosts_all (before getting unreachable)] ***************
ok: [foo1] => {
"ansible_play_hosts_all": [
"foo1",
"foo2",
"foo3"
]
}
ok: [foo2] => {
"ansible_play_hosts_all": [
"foo1",
"foo2",
"foo3"
]
}
TASK [Simulate unreachability] *************************************************
skipping: [foo1]
fatal: [foo2]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname foo2: nodename nor servname provided, or not known", "unreachable": true}
TASK [Print ansible_play_batch (after getting unreachable)] ********************
ok: [foo1] => {
"ansible_play_batch": [
"foo1"
]
}
TASK [Print ansible_play_hosts (after getting unreachable)] ********************
ok: [foo1] => {
"ansible_play_hosts": [
"foo1",
"foo3"
]
}
TASK [Print ansible_play_hosts_all (after getting unreachable)] ****************
ok: [foo1] => {
"ansible_play_hosts_all": [
"foo1",
"foo2",
"foo3"
]
}
PLAY [all] *********************************************************************
TASK [Print ansible_play_batch (before getting unreachable)] *******************
ok: [foo3] => {
"ansible_play_batch": [
"foo3"
]
}
TASK [Print ansible_play_hosts (before getting unreachable)] *******************
ok: [foo3] => {
"ansible_play_hosts": [
"foo1",
"foo2",
"foo3"
]
}
TASK [Print ansible_play_hosts_all (before getting unreachable)] ***************
ok: [foo3] => {
"ansible_play_hosts_all": [
"foo1",
"foo2",
"foo3"
]
}
TASK [Simulate unreachability] *************************************************
skipping: [foo3]
TASK [Print ansible_play_batch (after getting unreachable)] ********************
ok: [foo3] => {
"ansible_play_batch": [
"foo3"
]
}
TASK [Print ansible_play_hosts (after getting unreachable)] ********************
ok: [foo3] => {
"ansible_play_hosts": [
"foo1",
"foo2",
"foo3"
]
}
TASK [Print ansible_play_hosts_all (after getting unreachable)] ****************
ok: [foo3] => {
"ansible_play_hosts_all": [
"foo1",
"foo2",
"foo3"
]
}
PLAY RECAP *********************************************************************
foo1 : ok=6 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
foo2 : ok=3 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
foo3 : ok=6 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
- hosts: all
gather_facts: no
serial: 2
tasks:
- name: Print ansible_play_batch (before getting unreachable)
debug:
var: ansible_play_batch
- name: Print ansible_play_hosts (before getting unreachable)
debug:
var: ansible_play_hosts
- name: Print ansible_play_hosts_all (before getting unreachable)
debug:
var: ansible_play_hosts_all
- name: Simulate unreachability
command: /bin/true
when: fail
- name: Print ansible_play_batch (after getting unreachable)
debug:
var: ansible_play_batch
- name: Print ansible_play_hosts (after getting unreachable)
debug:
var: ansible_play_hosts
- name: Print ansible_play_hosts_all (after getting unreachable)
debug:
var: ansible_play_hosts_all
@ajalab
Copy link
Author

ajalab commented Jan 12, 2021

$ ansible --version
ansible 2.10.3
  config file = None
  configured module search path = ['/Users/koki/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)]
$ ansible-playbook -i hosts -b playbook-failure.yml > playbook-failure.log
$ ansible-playbook -i hosts -b playbook-unreachable.yml > playbook-unreachable.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment