簡體   English   中英

Ansible dnf 模塊返回成功,即使 dnf 失敗

[英]Ansible dnf module returns success even when dnf fails

  1. 這是我系統的初始 state:
  • 我安裝了 myrpm-2.0。
  • 此 rpm 僅創建一個文件。
  • /usr/share/myfile作為文件存在。
    /root# rpm -q myrpm
    myrpm-2.0-0.x86_64
    /root# rpm -ql myrpm-2.0-0.x86_64
    /usr/share
    /usr/share/myfile
    /root# ls -lrt /usr/share | grep myfile
    -rw-r--r--   1 root root     11 May 25 17:32 myfile
    /root#
  1. 現在我正在模擬錯誤情況。 我手動刪除了該文件並在其位置創建了一個目錄。
    /root# ls -lrt /usr/share | grep myfile
    drwxr-xr-x   2 root root   4096 May 25 18:33 myfile
    /root#
  1. 我准備了相同rpm的更高版本3.0,它復制了相同的文件。
    /root# rpm -ql /root/update/myrpm-3.0-0.x86_64.rpm
    /usr/share
    /usr/share/myfile
    /root#

4-Test-1:嘗試使用 ansible 的內置 dnf 模塊進行 rpm 升級。 以下是我的劇本:

/root# cat test.yaml
---
- hosts: localhost
  tasks:
    - name: update rpm
      dnf:
        name: "myrpm"
        state: latest
/root#

執行此 playbook 返回代碼為 0。

/root# ansible-playbook -vvv test.yaml
...
changed: [localhost] => {
    "changed": true,
    "invocation": {
        "module_args": {
            "allow_downgrade": false,
            "autoremove": false,
            "bugfix": false,
            "conf_file": null,
            "disable_excludes": null,
            "disable_gpg_check": false,
            "disable_plugin": [],
            "disablerepo": [],
            "download_dir": null,
            "download_only": false,
            "enable_plugin": [],
            "enablerepo": [],
            "exclude": [],
            "install_repoquery": true,
            "install_weak_deps": true,
            "installroot": "/",
            "list": null,
            "lock_timeout": 30,
            "name": [
                "myrpm"
            ],
            "releasever": null,
            "security": false,
            "skip_broken": false,
            "state": "latest",
            "update_cache": false,
            "update_only": false,
            "validate_certs": true
        }
    },
    "msg": "",
    "rc": 0,
    "results": [
        "Installed: myrpm-3.0-0.x86_64",
        "Removed: myrpm-2.0-0.x86_64"
    ]
}
META: ran handlers
META: ran handlers

PLAY RECAP *******************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

/root# echo $?
0
/root#

根據詳細日志,rc 為 0。 但是,我可以看到 dnf 命令失敗了。

/root# dnf history | head -n 3
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    27 |                          | 2022-05-25 18:39 | Upgrade        |    1 EE
/root# dnf history info 27 | tail -6
Packages Altered:
 ** Upgrade  myrpm-3.0-0.x86_64 @My_Update
    Upgraded myrpm-2.0-0.x86_64 @@System
Scriptlet output:
   1 error: unpacking of archive failed on file /usr/share/myfile: cpio: File from package already exists as a directory in system
   2 error: myrpm-3.0-0.x86_64: install failed
/root#

4-Test-2:我在與 3 完全相同的 state 中制作我的系統,並使用直接 dnf 命令而不是 playbook。

/root# dnf update myrpm
...
  Preparing        :                                                                              1/1
  Upgrading        : myrpm-3.0-0.x86_64                                                           1/2
Error unpacking rpm package myrpm-3.0-0.x86_64
error: unpacking of archive failed on file /usr/share/myfile: cpio: File from package already exists as a directory in system

  Cleanup          : myrpm-2.0-0.x86_64                                                           2/2
error: myrpm-3.0-0.x86_64: install failed

  Verifying        : myrpm-3.0-0.x86_64                                                           1/2
  Verifying        : myrpm-2.0-0.x86_64                                                           2/2

Failed:
  myrpm-3.0-0.x86_64

Error: Transaction failed
/root# echo $?
1
/root# 

關於為什么劇本沒有將任務顯示為失敗的任何線索?

才知道這是ansible高版本修復的bug,參考https://github.com/ansible/ansible/issues/77917

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM