【问题标题】:Running gather_facts: true fails with "uid not found: 1001"运行gather_facts:true 失败并显示“未找到uid:1001”
【发布时间】:2019-09-30 12:07:55
【问题描述】:

我有一个将gather_facts 设置为true 的ansible-playbook。但它无法获得uid。这是我得到的错误:

TASK [Gathering Facts] **************************************************************************************************************************************************************
The full traceback is:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 144, in run
    res = self._execute()
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 516, in _execute
    self._play_context = self._play_context.set_task_and_variable_override(task=self._task, variables=variables, templar=templar)
  File "/usr/lib/python2.7/site-packages/ansible/playbook/play_context.py", line 335, in set_task_and_variable_override
    new_info.remote_user = pwd.getpwuid(os.getuid()).pw_name
KeyError: 'getpwuid(): uid not found: 1001'

fatal: [localhost]: FAILED! => {
    "msg": "Unexpected failure during module execution.",
    "stdout": ""
}

现在,1001 uid 出现在设置中:

$ echo $UID
1001

我在容器中运行它,这可能是个问题吗?任何有助于调试的指针都值得赞赏。 TIA。

【问题讨论】:

  • 你能显示代码吗

标签: ansible


【解决方案1】:

我在容器中运行它,这可能是个问题吗?

虽然这不会自动造成问题,但它可能是相关的,因为您可以更轻松地将进程作为 docker 容器内的任意 UID 执行。你通常不会在虚拟机上看到这个问题,因为为了在虚拟主机上运行任何东西,你必须首先进行身份验证,这几乎总是涉及在/etc/passwd 中查找各种用户信息。但是,容器通常没有“登录”过程,因为它只是 Linux 命名空间的诡计

您可以通过运行docker run --rm -u 12345 ubuntu:18.04 id -a 自己尝试并观察uid=12345 gid=0(root) groups=0(root),但在/etc/passwd 中没有针对UID 12345 的条目(注意(something)uid= 结果之后丢失)

【讨论】:

  • 谢谢马修。是的,这就是问题所在。我修改了/etc/passwd 并能够运行剧本。你认为这是一个更清洁的解决方案还是应该有一些额外的步骤?
【解决方案2】:

2 个解决方案:

- hosts: all
  gather_facts: no

ansible_test:
  image: docker.io/major/ansible:fedora29
  script:
    - echo "tempuser:x:$(id -u):$(id -g):,,,:${HOME}:/bin/bash" >> /etc/passwd
    - echo "tempuser:x:$(id -G | cut -d' ' -f 2)" >> /etc/group
    - id
    - ansible-playbook -i hosts playbook.yml

https://major.io/2019/03/22/running-ansible-in-openshift-with-arbitrary-uids/

【讨论】:

    猜你喜欢
    • 2018-07-04
    • 1970-01-01
    • 1970-01-01
    • 2018-05-02
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多