Running command as newly created user

Hi,

I have a scenario where I need to create a new user, and then execute commands as that user. E.g.:

  • name: create user
    user: name=newUser password=hashedPass shell=/bin/bash
  • name: run command as user
    shell: echo $USER > ~/user.out
    remote_user: newUser

However, Ansible does not know how to ssh in as newUser. What is the preferred method for doing this?

Thanks, Jared

If you add an intermediate ‘authorized_keys’ to a key you already have access for that user, it should work.