Reputation: 7584
Specifically, I want to run most actions on host host
as my personal chris
user, but some commands as root
. I think become: true
wouldn't work well because chris
needs a password to become root
, and I don't want to have to enter this every time I deploy. My local public key is allowed to log into host
as either chris
or root
(I've put my public key in both /root/.ssh/authorized_keys
and /home/chris/.ssh/authorized_keys
).
Is there a common way to tell ansible to perform some commands as another user by ssh'ing as that user, rather than by becoming that user via sudo? Or am I stuck creating two separate hosts in my hosts.yml, one with ansible_user: chris
and one with ansible_user: root
?
Upvotes: 1
Views: 574
Reputation: 68329
ansible_user is a connection variable. See Controlling how Ansible behaves: precedence rules on how to declare or override the variable.
See detail in Ansible connects with default remote_user ...
Be aware that the best practice is to Disable Root Logins.
Upvotes: 1