Ansible dnfモジュール:「モジュールエラー」

Ansible dnfモジュール:「モジュールエラー」

私が見るものAnsible dnfモジュール失敗する。しかし、それは信頼できません。失敗したときにもう一度Ansibleを実行すると成功するようです。

私のシステムはFedora 29 Workstationです。 (詳細なバージョン情報は下記からご確認ください)

スクリプトでAnsibleを実行しています。ローカル接続を使用します。sudo ansible-playbook -c local ...

$ ./localhost alan-laptop playbooks/alan-laptop.yml 
[sudo] password for alan-sysop:
[DEPRECATION WARNING]: The use of 'static' has been deprecated. Use 
'import_tasks' for static inclusion, or 'include_tasks' for dynamic inclusion. 
This feature will be removed in version 2.12. Deprecation warnings can be 
disabled by setting deprecation_warnings=False in ansible.cfg.

PLAY [alan-laptop] *************************************************************

TASK [Gathering Facts] *********************************************************
ok: [alan-laptop]

TASK [repos-fedora : Check OS is Fedora] ***************************************
ok: [alan-laptop] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [repos-fedora : Configure Fedora repos using local cache] *****************
changed: [alan-laptop]

TASK [repos-fedora : Test "dnf check-update"] **********************************
changed: [alan-laptop]

TASK [sourcejedi.etckeeper : Install epel repo (needed for Centos)] ************
skipping: [alan-laptop]

TASK [sourcejedi.etckeeper : Install etckeeper] ********************************

fatal: [alan-laptop]: FAILED! => {"changed": false, "module_stderr": "<stdin>:17: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses\n", "module_stdout": "[master df9553e] saving uncommitted changes in /etc prior to dnf run\n Author: Alan Jenkins <[email protected]>\n 5 files changed, 79 insertions(+), 48 deletions(-)\n\n{\"msg\": \"Nothing to do\", \"changed\": false, \"results\": [\"Installed: etckeeper\"], \"rc\": 0, \"invocation\": {\"module_args\": {\"name\": [\"etckeeper\"], \"state\": \"present\", \"allow_downgrade\": false, \"autoremove\": false, \"bugfix\": false, \"disable_gpg_check\": false, \"disable_plugin\": [], \"disablerepo\": [], \"download_only\": false, \"enable_plugin\": [], \"enablerepo\": [], \"exclude\": [], \"installroot\": \"/\", \"install_repoquery\": true, \"security\": false, \"skip_broken\": false, \"update_cache\": false, \"update_only\": false, \"validate_certs\": true, \"conf_file\": null, \"disable_excludes\": null, \"list\": null, \"releasever\": null}}}\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 0}

[...]

「変更」作業が重要になるようです。これは私のdnfリポジトリファイルをインストール(そして確認)します。つまり、Ansibleを再実行すると、これらのタスクは自然に「変更」されません。作業を強制的に「変更」するためにリポジトリファイルを消去しました。初めて、これはdnfモジュールの欠陥を再現するようです。しかし、これまで何度も試してみましたが、常に欠陥を再現することはできません。

  1. 「MODULE FAILURE\nSee stdout/stderr for the 特定のエラー」というメッセージは、どこかに実際のエラーメッセージがあるはずですが、それが何であるかはわかりません。 Ansible dnfモジュールにバグがありますか?つまり、実際のエラーを報告しないという意味ですか?間違いなくサポート停止の警告は実際のエラーではありません。とにかく発生しますが、実際のエラーがある場合にのみ表示されますか?

  2. なぜ失敗したのですか?

    関連性があると思いmodule_stdoutますか?しなければならない有効なJSONですが、etckeeperのGitメッセージと混在していますか?私はそれが原因だとは思わない。なぜなら、時にはdnfモジュールがするからです。いいえ例に示すように、コミットされていない変更があっても失敗しますsudo etckeeper vcs diff

    また、これがPackageKitと衝突する可能性があると思いましたが...

    確認してみると、または私の全体Ansibleプレイブックと競合がないようですpkcon refresh force。どちらも手をつないでいるようです。sudo dnf check-update --refreshsudo dnf install etckeepersudo ansible localhost -m dnf -a "name=etckeeper state=present"

    さらに、その後もこのような障害が発生しますsystemctl mask --now --runtime packagekit.service。 (もう一度確認してみると、エラーが発生したときにサービスが実行されていませんでした。)


$ ansible --version
ansible 2.7.9
  config file = /home/alan-sysop/ansible/ansible.cfg
  configured module search path = ['/home/alan-sysop/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.2 (default, Mar 21 2019, 10:09:12) [GCC 8.3.1 20190223 (Red Hat 8.3.1-2)]
$ rpm -q ansible
ansible-2.7.9-1.fc29.noarch

ベストアンサー1

module_stdoutQ:有効なJSONである必要があるようですが、etckeeperのGitメッセージと混在しています。関係ありますか?

ㅏ。はい

Ansibleモジュール[...]は終了する前にJSON文字列をstdoutに出力し、ansibleに情報を返します。

問題は、開いている角かっこで始まるetckeeperからのメッセージが原因で特に発生します。

[master df9553e] saving uncommitted changes in /etc prior to dnf run
 Author: Alan Jenkins <[email protected]>
 5 files changed, 79 insertions(+), 48 deletions(-)

Ansibleは、jsonではなくヘッダー行を自動的にスキップして同様の問題を解決することを目的としています。[ただし、JSONドキュメントの起動に有効な文字があります。バラよりlib/ansible/module_utils/json_utils.py

def _filter_non_json_lines(data):
    '''
    Used to filter unrelated output around module JSON output, like messages from
    tcagetattr, or where dropbear spews MOTD on every single command (which is nuts).

    Filters leading lines before first line-starting occurrence of '{' or '[', and filter all
    trailing lines after matching close character (working from the bottom of output).
    '''

おすすめ記事