Christopher Shroba
Christopher Shroba

Reputation: 7584

How can I auth as different users without creating multiple hosts in Ansible?

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

Answers (1)

Vladimir Botka
Vladimir Botka

Reputation: 68329

Upvotes: 1

Related Questions