Reputation: 3619
I have a ansible-playbook that has gather_facts set to true. But it fails to get the uid. Here is the error I am getting:
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": ""
}
Now, the 1001 uid is present in the setup:
$ echo $UID
1001
I am running this inside a container, could that be an issue? Any pointers to help debug this are appreciated. TIA.
Upvotes: 1
Views: 1884
Reputation: 1
2 solutions:
- hosts: all
gather_facts: no
or
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/
Upvotes: 0
Reputation: 33203
I am running this inside a container, could that be an issue?
While that doesn't automatically make it a problem, it is perhaps relevant since you can more easily execute a process as an arbitrary UID inside a docker container. You don't typically see that problem on a virtual machine because in order to run anything on the virtual host, you have to actually be authenticated first, which almost always involves looking up all kinds of user information in /etc/passwd
. However, there is usually no "login" process for a container, since it is just Linux namespace trickery
You can try it yourself by running docker run --rm -u 12345 ubuntu:18.04 id -a
and observe uid=12345 gid=0(root) groups=0(root)
but there is no entry in /etc/passwd
for UID 12345
(notice the missing (something)
after the uid=
result)
Upvotes: 1