Ansible変数に対して呼び出すことができるすべてのメソッドはどこで見つけることができますか?

Ansible変数に対して呼び出すことができるすべてのメソッドはどこで見つけることができますか?

以下は簡単なAnsibleスクリプトです:

- name: this command prints FAILED when it fails
  command: /usr/bin/example-command -x -y -z
  register: command_result
  failed_when: "'FAILED' in command_result.stderr"

これで、変数command_resultにメソッドがあることがわかりましたstderr。しかし、すべてのメソッドのリストをどのように取得できますか?

ベストアンサー1

debugダンプ変数を使用できます。

- name: this command prints FAILED when it fails
  command: /usr/bin/example-command -x -y -z
  register: command_result
  failed_when: "'FAILED' in command_result.stderr"
- name: dump command_result
  debug: var=command_result

すると、次のように出力されます。

TASK: [dump command_result] **************************************************************
ok: [hostname] => {
    "command_result": {
        "changed": false,
        "cmd": "/usr/bin/example-command -x -y -z",
        "delta": "0:00:00.018233",
        "end": "2015-05-07 09:33:08.444674",
        "invocation": {
            "module_args": "/usr/bin/example-command -x -y -z",
            "module_name": "command"
        },
        "rc": 0,
        "start": "2015-05-07 09:33:08.426441",
        "stderr": "",
        "stdout": "whatever",
        "stdout_lines": [
            "whatever"
        ],
        "warnings": []
    }
}

おすすめ記事