Ansible: 「dictobject」は、when節2.3RC1に属性がありません。

作成日 2017年03月17日  ·  2コメント  ·  ソース: ansible/ansible

問題の種類
  • バグレポート
コンポーネント名

ANSIBLEバージョン
ansible 2.3.0.0 (stable-2.3 923c9ef17c) last updated 2017/03/17 09:12:40 (GMT +1000)
  config file = /apps/dev/playbook/jordan/mr-ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Sep 23 2016, 14:23:49) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
構成

標準

OS /環境

RHEL 6.7

概要

これはバグではないかもしれませんが、古いバージョンでは解決したものですが、モジュールによって登録された変数(when句を含む)が定義されているかどうかを確認し、その後サブディクト値を取得する場合は、Ansible 2.3RC1を使用します2.3では失敗しますが、2.2以下では正常に動作します。 これは特に、変数を登録するモジュールが何らかの理由でスキップされ、後続のタスクが変数が定義されているかどうかを確認してからサブキーを取得した場合に発生します。

再現する手順

プレイブックの例

---
- name: test
  hosts: localhost
  connection: local

  tasks:
  - name: module that won't run
    stat:
      path: /apps/tmp
    register: test
    when: False

  - name: debug of var
    debug:
      var: test

  - name: test with conditional
    debug:
      msg: A
    when: test is defined and test.stat.exists
期待される結果

Ansible2.2.1.0を使用する場合

ansible 2.2.1.0
  config file = /cygdrive/d/dev/jordan/ansible.cfg
  configured module search path = Default w/o overrides
PLAY [test] ********************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [module that won't run] ***************************************************
task path: /cygdrive/d/dev/jordan/2.3tests.yml:7
skipping: [localhost] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}

TASK [debug of var] ************************************************************
task path: /cygdrive/d/dev/jordan/2.3tests.yml:13
ok: [localhost] => {
    "test": {
        "changed": false,
        "skip_reason": "Conditional check failed",
        "skipped": true
    }
}

TASK [test with conditional] ***************************************************
task path: /cygdrive/d/dev/jordan/2.3tests.yml:17
skipping: [localhost] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0
実績
-実際に何が起こったのですか? 可能であれば、余分な冗長性で実行します(-vvvv)

PLAY [test] ************************************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************************
Friday 17 March 2017  15:20:42 +1000 (0:00:00.039)       0:00:00.039 **********
ok: [localhost]
META: ran handlers

TASK [module that won't run] *******************************************************************************************************************************************************
task path: /apps/dev/playbook/jordan/mr-ansible/test.yml:7
Friday 17 March 2017  15:20:44 +1000 (0:00:01.093)       0:00:01.133 **********
skipping: [localhost] => {"changed": false, "skip_reason": "Conditional result was False", "skipped": true}

TASK [debug of var] ****************************************************************************************************************************************************************
task path: /apps/dev/playbook/jordan/mr-ansible/test.yml:13
Friday 17 March 2017  15:20:44 +1000 (0:00:00.012)       0:00:01.145 **********
ok: [localhost] => {
    "changed": false,
    "test": {
        "changed": false,
        "skip_reason": "Conditional result was False",
        "skipped": true
    }
}

TASK [test with conditional] *******************************************************************************************************************************************************
task path: /apps/dev/playbook/jordan/mr-ansible/test.yml:17
Friday 17 March 2017  15:20:44 +1000 (0:00:00.034)       0:00:01.180 **********
fatal: [localhost]: FAILED! => {"failed": true, "msg": "The conditional check 'test is defined and test.stat.exists' failed. The error was: error while evaluating conditional (test is defined and test.stat.exists): 'dict object' has no attribute 'stat'\n\nThe error appears to have been in '/apps/dev/playbook/jordan/mr-ansible/test.yml': line 17, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n  - name: test with conditional\n    ^ here\n"}

PLAY RECAP *************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=1
affects_2.3 bug

最も参考になるコメント

考えられる誤解

こんにちは!

Ansibleにご提出いただきありがとうございます。 それは私たちにとって心から多くのことを意味します。

あなたが提出したチケットは、記載されているものとは少し異なる動作をするため、多少誤解されていると思われます。

将来的には、これはユーザーリストにより適したトピックになる可能性があります。上記についてさらにサポートが必要な場合は、ここに投稿することもできます。

'stat'タスクをスキップしているため、定義済みの辞書としてtestれますが、 statキーがないため、正しいエラーメッセージが表示されます。 このような問題を回避するには、次のものが必要です。

  when: test is defined and 'stat' in test and test.stat.exists

これとAnsibleに関心をお寄せいただき、ありがとうございます。

全てのコメント2件

考えられる誤解

こんにちは!

Ansibleにご提出いただきありがとうございます。 それは私たちにとって心から多くのことを意味します。

あなたが提出したチケットは、記載されているものとは少し異なる動作をするため、多少誤解されていると思われます。

将来的には、これはユーザーリストにより適したトピックになる可能性があります。上記についてさらにサポートが必要な場合は、ここに投稿することもできます。

'stat'タスクをスキップしているため、定義済みの辞書としてtestれますが、 statキーがないため、正しいエラーメッセージが表示されます。 このような問題を回避するには、次のものが必要です。

  when: test is defined and 'stat' in test and test.stat.exists

これとAnsibleに関心をお寄せいただき、ありがとうございます。

このページは役に立ちましたか?
0 / 5 - 0 評価