The Ansible connects to my servers using a non-root user. The goal is for this non-root user to be able to install yum packages. For this, it needs sudo privileges, so I've configured the sudoers file to allow the use of yum without a password for that user.
test_user ALL=(ALL) NOPASSWD: /usr/bin/yum
When I log in to one of the target servers with the specified user, the installation works without any issues.
[test-user@TESTHOST01~]$ sudo yum update
Updating Subscription Management repositories.
Microsoft Tools for RedHat 8 33 kB/s | 2.0 kB 00:00
Oracle_yum_repository 31 kB/s | 2.0 kB 00:00
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs) 86 kB/s | 4.5 kB 00:00
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs) 68 kB/s | 4.1 kB 00:00
DockerCE_8Server 40 kB/s | 2.0 kB 00:00
EPEL8_REPO 39 kB/s | 2.3 kB 00:00
Dependencies resolved.
Nothing to do.
Complete!
If, however, I try to install using Ansible, it fails.
Related playbook part:
- name: Install docker
ansible.builtin.yum:
name: "{{ packages }}"
state: present
vars:
packages:
- git
- containerd.io-1.6.9-3.1.el8
- docker-ce-cli-1:20.10.20-3.el8
- docker-ce-rootless-extras-20.10.20-3.el8
- docker-compose-plugin-2.12.0-3.el8
become: true
become_user: root
become_method: sudo
Error I got:
TASK [ans_rol_docker_swarm : Install docker] ***********************************
fatal: [10.5.237.14]: FAILED! => {"msg": "Missing sudo password"}
fatal: [10.5.237.10]: FAILED! => {"msg": "Missing sudo password"}
fatal: [10.5.237.15]: FAILED! => {"msg": "Missing sudo password"}
Related versions:
Run ansible --version
ansible --version
shell: /usr/bin/bash -e {0}
env:
ANSIBLE_CONFIG: .github/workflows/ansible/ansible.cfg
GIT_SSH_COMMAND: ssh -o StrictHostKeyChecking=no
ansible [core 2.13.13]
config file = None
configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
jinja version = 3.1.3
libyaml = True
[test-user@TESTHOST01~]$ cat /etc/os-release
NAME="Red Hat Enterprise Linux"
VERSION="8.9 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.9"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux 8.9 (Ootpa)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:8::baseos"
HOME_URL="https://www.redhat.com/"
DOCUMENTATION_URL="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_BUGZILLA_PRODUCT_VERSION=8.9
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8.9"