0

I have a following situation - I need to deploy an app on the ec2 isntance with ansible. The way we have ec2 setup is that it does not allow ssh'ing as root user. However, when I launch ansible on local machine, I need to run it as root user. Here is snippet of the playbook:

  - name: install app
    hosts: ec2
    remote_user: sshUser
    gather_facts: True
    roles: 
       ...

Now, it works if I set ask-pass=true and it prompts me to enter the password. However, I was wondering if I could set this programmatic-ally ? I'm guessing I have to do it via setting the inventory with ssh_user, once I'll get the IP. Not sure if it is a right way to do it or if there are better/simpler ways.

Thank you

1 Answer 1

0

Don't know if I've understood well. If you need to execute commands as root, just add this to your playbook:

sudo: true

This will execute ansible commands in sudo mode (default user is root, but you can set a different sudo user using the directive: sudo_user).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.