无法在 CentOS 上的 Ansible 中使用 dnf 安装 mysql-server

无法在 CentOS 上的 Ansible 中使用 dnf 安装 mysql-server

我需要安装 mysql-server,选择的方法是使用 Ansible,因为它简化了流程。但在安装过程中,我发现了这个问题,但无法调试。我的 YAML 文件是:

- name: Install mysql-server
    dnf:
      name: mysql-server
      state: present

但这给出了一个奇怪的错误。

fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "warning: /var/cache/dnf/mysql56-community-e7223972839acae4/packages/mysql-community-client-5.6.51-2.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Traceback (most recent call last):
  File \"/home/aunzaidi/.ansible/tmp/ansible-tmp-1637891029.2032368-4612-101264433776442/AnsiballZ_dnf.py\", line 100, in <module>
    _ansiballz_main()
  File \"/home/aunzaidi/.ansible/tmp/ansible-tmp-1637891029.2032368-4612-101264433776442/AnsiballZ_dnf.py\", line 92, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File \"/home/aunzaidi/.ansible/tmp/ansible-tmp-1637891029.2032368-4612-101264433776442/AnsiballZ_dnf.py\", line 41, in invoke_module
    run_name='__main__', alter_sys=True)
  File \"/usr/lib64/python2.7/runpy.py\", line 176, in run_module
    fname, loader, pkg_name)
  File \"/usr/lib64/python2.7/runpy.py\", line 82, in _run_module_code
    mod_name, mod_fname, mod_loader, pkg_name)
  File \"/usr/lib64/python2.7/runpy.py\", line 72, in _run_code
    exec code in run_globals
  File \"/tmp/ansible_dnf_payload_p9Z365/ansible_dnf_payload.zip/ansible/modules/dnf.py\", line 1363, in <module>
  File \"/tmp/ansible_dnf_payload_p9Z365/ansible_dnf_payload.zip/ansible/modules/dnf.py\", line 1352, in main
  File \"/tmp/ansible_dnf_payload_p9Z365/ansible_dnf_payload.zip/ansible/modules/dnf.py\", line 1326, in run
  File \"/tmp/ansible_dnf_payload_p9Z365/ansible_dnf_payload.zip/ansible/modules/dnf.py\", line 1230, in ensure
  File \"/usr/lib/python2.7/site-packages/dnf/base.py\", line 2275, in _get_key_for_package
    keys = dnf.crypto.retrieve(keyurl, repo)
  File \"/usr/lib/python2.7/site-packages/dnf/crypto.py\", line 176, in retrieve
    with dnf.util._urlopen(keyurl, repo=repo) as handle:
  File \"/usr/lib/python2.7/site-packages/dnf/util.py\", line 130, in _urlopen
    raise IOError(str(e))
IOError: Cannot download file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql: All mirrors were tried
", "module_stdout": "", "msg": "MODULE FAILURE
See stdout/stderr for the exact error", "rc": 1}

我找不到与此相关的任何结果或论坛。这应该是直截了当的。即使当我使用“-vvvvv”运行 Ansible 命令时,我也会收到以下错误:ansible-playbook -vvvvv ~/ansible/playbooks/starfish.yml

TASK [Install mysql-server] ******************************************************************************************************************************************************************
task path: /home/aunzaidi/ansible/playbooks/starfish.yml:35
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: aunzaidi
<localhost> EXEC /bin/sh -c 'echo ~aunzaidi && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/aunzaidi/.ansible/tmp `"&& mkdir "` echo /home/aunzaidi/.ansible/tmp/ansible-tmp-1637891456.166621-4897-257063194144455 `" && echo ansible-tmp-1637891456.166621-4897-257063194144455="` echo /home/aunzaidi/.ansible/tmp/ansible-tmp-1637891456.166621-4897-257063194144455 `" ) && sleep 0'
Using module file /usr/local/lib/python3.6/site-packages/ansible/modules/dnf.py
<localhost> PUT /home/aunzaidi/.ansible/tmp/ansible-local-4695ow_qhed0/tmp4jtykhs2 TO /home/aunzaidi/.ansible/tmp/ansible-tmp-1637891456.166621-4897-257063194144455/AnsiballZ_dnf.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/aunzaidi/.ansible/tmp/ansible-tmp-1637891456.166621-4897-257063194144455/ /home/aunzaidi/.ansible/tmp/ansible-tmp-1637891456.166621-4897-257063194144455/AnsiballZ_dnf.py && sleep 0'
<localhost> EXEC /bin/sh -c 'sudo -H -S -n  -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-kgdvjtjhvcvmedzecrzshnfzzpgijvwy ; /usr/bin/python /home/aunzaidi/.ansible/tmp/ansible-tmp-1637891456.166621-4897-257063194144455/AnsiballZ_dnf.py'"'"' && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/aunzaidi/.ansible/tmp/ansible-tmp-1637891456.166621-4897-257063194144455/ > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "warning: /var/cache/dnf/mysql56-community-e7223972839acae4/packages/mysql-community-client-5.6.51-2.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY\nTraceback (most recent call last):\n  File \"/home/aunzaidi/.ansible/tmp/ansible-tmp-1637891456.166621-4897-257063194144455/AnsiballZ_dnf.py\", line 100, in <module>\n    _ansiballz_main()\n  File \"/home/aunzaidi/.ansible/tmp/ansible-tmp-1637891456.166621-4897-257063194144455/AnsiballZ_dnf.py\", line 92, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/aunzaidi/.ansible/tmp/ansible-tmp-1637891456.166621-4897-257063194144455/AnsiballZ_dnf.py\", line 41, in invoke_module\n    run_name='__main__', alter_sys=True)\n  File \"/usr/lib64/python2.7/runpy.py\", line 176, in run_module\n    fname, loader, pkg_name)\n  File \"/usr/lib64/python2.7/runpy.py\", line 82, in _run_module_code\n    mod_name, mod_fname, mod_loader, pkg_name)\n  File \"/usr/lib64/python2.7/runpy.py\", line 72, in _run_code\n    exec code in run_globals\n  File \"/tmp/ansible_dnf_payload_nxJSO1/ansible_dnf_payload.zip/ansible/modules/dnf.py\", line 1363, in <module>\n  File \"/tmp/ansible_dnf_payload_nxJSO1/ansible_dnf_payload.zip/ansible/modules/dnf.py\", line 1352, in main\n  File \"/tmp/ansible_dnf_payload_nxJSO1/ansible_dnf_payload.zip/ansible/modules/dnf.py\", line 1326, in run\n  File \"/tmp/ansible_dnf_payload_nxJSO1/ansible_dnf_payload.zip/ansible/modules/dnf.py\", line 1230, in ensure\n  File \"/usr/lib/python2.7/site-packages/dnf/base.py\", line 2275, in _get_key_for_package\n    keys = dnf.crypto.retrieve(keyurl, repo)\n  File \"/usr/lib/python2.7/site-packages/dnf/crypto.py\", line 176, in retrieve\n    with dnf.util._urlopen(keyurl, repo=repo) as handle:\n  File \"/usr/lib/python2.7/site-packages/dnf/util.py\", line 130, in _urlopen\n    raise IOError(str(e))\nIOError: Empty mirrorlist and no basepath specified!\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

我还将分享我的整个 YAML“starfish.yml”文件,以防需要。 海星.yml。任何帮助将不胜感激。

答案1

我只能通过将包管理器从 dnf 更改为 yum 来解决这个问题。我不确定为什么这会产生问题,因为我之前在 CentOS 7.9 上使用过相同的脚本。无论如何,我通过实现以下代码来更改它:

- name: Install mysql-server
    yum:
      name: mysql-server
      state: present

相关内容