使用 slurm 用户运行 Ansible:How to fix ansible.legacy.setup failed to execute?

问题描述 投票:0回答:1
TASK [Gathering Facts] *********************************************************
task path: /opt/playbook/site.yml:1
Using module file /usr/local/lib/python3.10/dist-packages/ansible/modules/setup.py
Pipelining is enabled.
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: slurm
<localhost> EXEC /bin/sh -c 'sudo -H -S -n  -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-mvloemssulwwmnnhtatxivyevcbshjsb ; /usr/bin/python3'"'"' && sleep 0'
fatal: [localhost]: FAILED! => {
    "ansible_facts": {},
    "changed": false,
    "failed_modules": {
        "ansible.legacy.setup": {
            "failed": true,
            "module_stderr": "sudo: a password is required\n",
            "module_stdout": "",
            "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
            "rc": 1
        }
    },
    "msg": "The following modules failed to execute: ansible.legacy.setup\n"
}

剧本由 slurm 用户在节点启动时执行。但是,它在收集事实时失败了,我不确定问题出在哪里。显然 sudo 有问题。我正在寻找更有效地调试它的方法。

剧本在普通 ubuntu 用户下运行没有问题。

ansible slurm
1个回答
0
投票

@natan——我认为如果你不尝试如此直接地调用

sudo
可能会更好。此外,您可能不需要成为 root 用户即可执行
setup
.

这是我的很多剧本中的标题:

- name: Initial node setup
  hosts: localhost
  connection: local
  gather_facts: yes

  tasks:
  - name: Configure the machine...

关键事项:

  1. hosts: localhost
    ——这是您唯一正在使用的机器。
  2. connection: local
    -- 避免使用
    ssh
    连接到它已经在执行的机器上。
  3. gather_facts: yes
    ——你可以使用它来获取你的
    setup
    事实,你不需要成为 root。

这就剩下后续操作如何成为root的问题了。 传统上,连接参数(包括密码,如果不可避免)已在清单文件中提供。 您可以在您的物品栏或您的剧本中设置

ansible_become_password
,但您永远不应该使用纯文本形式的密码。 然后,对于需要root才能成功的任务,可以使用:

become: yes

我推荐此 Ansible 页面以获取更多信息:Ansible:了解权限升级

© www.soinside.com 2019 - 2024. All rights reserved.