I am migrating to a new architecture and I have provisioned my servers with an ansible playbook. I am also using ansible to deploy my source code.
I want to be able to reload nginx when the configuration change without having to :
give sudo rights on ALL commands to the deploy user
having to pass a become-pass in the command line
In my previous installation, I was doing everything manually and I had added this settings to allow my deployment user to reload the nginx configuration :
You can use ansible-vault to encrypt the host_vars file that contains
the become password, and either enter the vault password on execution
or have ansible read it from some file.
But that might not achieve what you want to do. So, what is your goal?
Do you want to restrict the one calling ansible to only be able to
reload nginx?
Then, as Matt said, using the raw module with an explicit sudo call,
that is allowed in /etc/sudoers might work (but is kind of ugly, of
course).
Yes my goal was to restrict on the OS side the commands the deployment user is allowed to execute.
I did not know the raw module. i am looking into it. It does not seem “ugly”
I think that it is quite a drawback on Ansible. If you use it for code shipping, you will have to do some tasks which needs privileges escalation (reload nginx or something else). And the people who are doing the delivery are not necessary engineers who should have access to all commands with a simple sudo. But if this raw module allows me to do this, so big up Ansible !!!
Thanks, I am looking at the raw module which seems to suite my need. And what about the shell module with a previously delivered shell script containing my reload nginx command ? Would it work ?
If you do not need to do anything else via ansible (at least the
people you mention) then raw module or shell with a script might be best.
As a side not, using a git repository with a post-receive hook that
might be an option for people more used to git than to sudo...
Depends on your exact environment, so YMMV.