I have a weird issue where I cant start or stop a service using systemd module. I get the following error if I run the ansible task:
"Unable to stop service inubit.service: Failed to stop inubit.service: Connection timed out\nSee system logs and 'systemctl status inubit.service' for details."
The user "integration" that should run the task has the sudo permission. If I run the commands with integration user manually on the machine or use ansible command task, they work.
sudo systemctl start inubit.service
sudo systemctl stop inubit.service
/etc/sudoers:
integration ALL=NOPASSWD:/bin/systemctl restart inubit
integration ALL=NOPASSWD:/bin/systemctl start inubit
integration ALL=NOPASSWD:/bin/systemctl stop inubit
integration ALL=NOPASSWD:/bin/systemctl status inubit
integration ALL=NOPASSWD:/bin/systemctl restart inubit.service
integration ALL=NOPASSWD:/bin/systemctl start inubit.service
integration ALL=NOPASSWD:/bin/systemctl stop inubit.service
integration ALL=NOPASSWD:/bin/systemctl status inubit.service
The task:
- name: Stop inubit service if running
ansible.builtin.systemd:
name: inubit.service
state: stopped
become: true
become_user: integration
Your user 'integration' may indeed have the permissions to run commands via sudo, i.e. to run commands as another user, but the user itself may not have appropriate permissions to stop systemd services.
Your ansible task is equivalent to the command sudo -u integration systemctl stop inubit.service
1.
Try removing "become_user" or changing it to "become_user: root".