Isso parece errado
Seu exemplo adiciona outro caminho ao seu playbook. Se o systemd não estiver instalado, a saída será diferente de se estiver instalada. E após a primeira execução, ele será instalado. Isso vai contra o princípio ansioso que diz:
Idempotency
An operation is idempotent if the result of performing it once is exactly the same as the result of performing it repeatedly without any intervening actions.
Se você ainda fizer isso, torne-o o mais explícito possível
Eu sugiro que você execute um comando which systemctl
e registre a saída. Verifique a saída para instalar o systemd e falhe com uma tarefa de falha.
Esta ainda é uma questão muito interessante
Eu acho que não há documentação real e temos que investigar.
Espero ter encontrado todos os casos :) mas não posso preencher o gráfico agora.
playbook.yml:
---
- name: test some stuff
hosts: all
tasks:
- include_tasks: tasks.yml
with_items:
- { data: ping, changed: true }
- { data: ping, changed: false }
- { data: crash, changed: true }
- { data: crash, changed: false }
tasks.yml
---
- name: Check for command_result is defined and command_result
ping:
data: "{{ item.data }}"
register: command_result
changed_when: item.changed
failed_when: command_result is defined and command_result
ignore_errors: true
- name: Check for command_result is defined and command_result
file:
path: ./file
register: command_result
changed_when: item.changed
failed_when: command_result is defined and command_result
ignore_errors: true
- name: Check for command_result
ping:
data: "{{ item.data }}"
register: command_result
changed_when: item.changed
failed_when: command_result
ignore_errors: true
- name: Check for command_result
file:
path: ./file
register: command_result
changed_when: item.changed
failed_when: command_result
ignore_errors: true
- name: Check for command_result.changed is defined and command_result.changed
ping:
data: "{{ item.data }}"
register: command_result
changed_when: item.changed
failed_when: command_result.changed is defined and command_result.changed
- name: Check for command_result.changed is defined and command_result.changed
ping:
data: "{{ item.data }}"
register: command_result
changed_when: item.changed
failed_when: command_result.changed is defined and command_result.changed
ignore_errors: true
- name: Check for command_result.changed
ping:
data: "{{ item.data }}"
register: command_result
changed_when: item.changed
failed_when: command_result.changed
ignore_errors: true
- name: Check for command_result.changed
file:
path: ./file
register: command_result
changed_when: item.changed
failed_when: command_result.changed
ignore_errors: true