6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ansible task の状態の種類 ( ok / changed / failed / skipped / ignoring )

Last updated at Posted at 2018-07-12

図解

image.png

DO は SKIP の反対語として、適当につけた名前。

DO

タスクが実行される。なぜならタスクは実行するためのもの。
結果は三種類に分かれる。

DO -> OK

タスクが成功。

DO -> CHANGED

タスクでなにか変化が起きた時のステータス。
たとえばファイルの新規設置をしたり、パーミッション変更をしたり。

DO -> FAILED

タスクが失敗した時のステータス。
その後の挙動は二つに分かれる。

FAILED -> EXIT

次以降のタスクにも進まず、そこで終了する。

FAILED -> IGNORING

失敗を無視して次のタスク実行に進む。

SKIP

タスクをスキップする。何もしない。つまり OK / CHANGED / FAILED の結果もない。

Playbookの例

- hosts:
    - localhost
  tasks:
    - name: skip
      debug:
        msg: this task will be skipped
      when: false

    - name: do -> ok
      debug:
        msg: task has done and return ok

    - name: do -> changed
      debug:
        msg: task has done and return changed
      changed_when: yes

    - name: do -> failed -> ignoring
      debug:
        msg: task has done, return failed, and continue to next task
      failed_when: yes
      ignore_errors: yes
 
    - name: do -> failed -> exit
      debug:
        msg: task has done, return failed, and exit ( do not continue to next task )
      failed_when: yes
 
    - name: after failed task
      debug:
        msg: task will be not run because previous task has failed and exit

実行結果例

TASK [skip] **************************************************************************************************************************************
skipping: [localhost]

TASK [do -> ok] **********************************************************************************************************************************
ok: [localhost] => {
    "msg": "task has done and return ok"
}

TASK [do -> changed] *****************************************************************************************************************************
changed: [localhost] => {
    "msg": "task has done and return changed"
}

TASK [do -> failed -> ignoring] ******************************************************************************************************************
fatal: [localhost]: FAILED! => {
    "msg": "task has done, return failed, and continue to next task"
}
...ignoring

TASK [do -> failed -> exit] **********************************************************************************************************************
fatal: [localhost]: FAILED! => {
    "msg": "task has done, return failed, and exit ( do not continue to next task )"
}
	to retry, use: --limit @/Users/yuma/projects/study/ansible/playbooks/task_state.retry

PLAY RECAP ***************************************************************************************************************************************
localhost                  : ok=4    changed=1    unreachable=0    failed=1   

環境

  • ansible 2.6.1

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?