LoginSignup
5

More than 5 years have passed since last update.

`when` で `register` が skip されなくてつらい

Posted at

したのような playbook を書いて実行した時、

- name:  debug
  hosts: all
  connection: local
  gather_facts: false

  tasks:
    - shell: echo 'foo'
      register: result
      when: true

    - shell: echo 'bar'
      register: result
      when: false

    - debug: var=result

debugの結果を

TASK: [debug var=result] ******************************************************
ok: [localhost] => {
    "result": {
        "changed": true,
        "cmd": "echo 'foo' ",
        "delta": "0:00:00.004067",
        "end": "2014-07-17 23:30:29.543649",
        "invocation": {
            "module_args": "echo 'foo'",
            "module_name": "shell"
        },
        "rc": 0,
        "start": "2014-07-17 23:30:29.539582",
        "stderr": "",
        "stdout": "foo",
        "stdout_lines": [
            "foo"
        ]
    }
}

↑こういうのだと期待してたのに、実際のところ

PLAY [debug] ******************************************************************

TASK: [shell echo 'foo'] ******************************************************
changed: [localhost]

TASK: [shell echo 'bar'] ******************************************************
skipping: [localhost]

TASK: [debug var=result] ******************************************************
ok: [localhost] => {
    "result": {
        "changed": false,
        "skipped": true
    }
}

こうなってしまう。

いや、registerごとskipしてほしいんですけど。
ある変数にregisterするactionの実行を条件によって分岐させたいんだけどいいやりかたないかなぁ。

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
5