![가능한 result.failed 및 failed_when, result.changed 및 selected_when 등](https://linux55.com/image/128487/%EA%B0%80%EB%8A%A5%ED%95%9C%20result.failed%20%EB%B0%8F%20failed_when%2C%20result.changed%20%EB%B0%8F%20selected_when%20%EB%93%B1.png)
Ansible은 버전 1.4 이상에서 다음과 같이 이 동작을 지정하는 방법을 제공합니다.
- name: Fail task when the command error output prints FAILED command: /usr/bin/example-command -x -y -z register: command_result failed_when: "'FAILED' in command_result.stderr"
하지만 흔한반환 값이미 포함되어 .failed
있으며 .changed
.
내 생각에는 이러한 특성은 모순적이다. 공식적인 해결책이 있나요? Ansible은 그중 하나를 먼저 평가하고 후자에 영향을 미치도록 failed_when
정의 합니까? changed_when
다른 것의 효과를 보지 않고 둘 다 평가하는 것을 정의합니까?
예를 들어 정의된 동작은 무엇입니까?
command_result.failed
failed_when
표현 내에서command_result.changed
changed_when
표현 내에서command_result.failed
changed_when
표현 내에서command_result.changed
changed_when
표현 내에서
예를 들어 세 번째 결과를 좀 더 명확하게 설명하자면 다음 결과가 얼마나 잘 정의되어 있는지(신뢰할 수 있게)에 관심이 있습니다.
- package:
name: systemd
state: present
check_mode: yes
register: command_result
failed_when: command_result.changed
제가 Ansible 2.0 이상에 관심이 있다고 가정해 보겠습니다.
답변1
이건 옳지 않은 것 같아
귀하의 예는 플레이북에 다른 경로를 추가합니다. systemd가 설치되어 있지 않으면 설치했을 때와 출력이 달라집니다. 첫 실행 후 설치됩니다. 이는 Ansible 원칙을 위반합니다.
멱등성
연산을 한 번 수행한 결과가 중간 연산 없이 반복적으로 연산을 수행한 결과와 정확히 같으면 해당 연산은 멱등성이 있습니다.
그래도 이 작업을 수행하는 경우 최대한 명시적으로 설명해주세요.
명령을 실행 which systemctl
하고 출력을 등록하는 것이 좋습니다. systemd 설치 출력을 확인하면 실패한 작업으로 인해 실패합니다.
이것은 여전히 매우 흥미로운 질문입니다.
실제 문서가 없는 것 같아요. 조사해야 할 것 같아요.
모든 사건을 다 잡았으면 좋겠습니다 :) 그런데 지금은 차트를 채울 수 없습니다.
script.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 }
작업.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