In advance thank you for your help.
I use ansible into my CI gitlab and I need to restart a linux service witout become root.
When I run my playbook, I use a local user for my deploiement "deploy" and this user can send many commands like:
sudo systemctl status my_application sudo systemctl start my_application sudo systemctl stop my_application sudo systemctl restart my_application
However, the problem that we found is when I use the following code as "handler"
---
# handlers file for my application
- name: "Restart application"
systemd:
name: "{{ app_name }}"
enabled: yes
daemon-reload: yes
state: restarted
become: true
In fact, when you specify "become: true" under the task, ansible try to run "sudo -s" in order to become root... but in my case I don't want to be root, I only want to run a command with sudo ...
RUNNING HANDLER [app01 : Restart application] ********************
fatal: [XXXXXXXX]: FAILED! => {"msg": "Missing sudo password"}
But my user "deploy" is authorized into sudoers configuration to send the following commands without password:
sudo systemctl status my_application sudo systemctl start my_application sudo systemctl stop my_application sudo systemctl restart my_application
My goal is to use the ansible module "systemd" and I cannot use "shell" to solve my issue.
I hope that my explanation is clear ...
Thanks,