Two remote users one for production and one from staging

Hi there,

I’ve been playing with ansible for the last month, and now I finally have the opportunity to provision our small cluster with it.
Bye bye puppet.

So far the instructions are pretty clear. But I have some questions on best practices.
I’m following the directory layout from best practice docs and it looks great.

However, I’m still unsure how can I reuse the playbook for development and production and not duplicating code

I’m using vagrant for dev and aws for production
So when using vagrant it’s easy to create a new user and do all the stuff using ‘vagrant’ user, then I create our universal user.

However, I’m finding a bit difficult to reuse the same playbook for provisioning aws ec2.
Since I have to change a different remote user: ubuntu and add the same universal user. Can I create a variable that changes based on the context that is run?
Where can I find that info?

`

  • name: Webserver with MySQL Client, Nginx, and PHP-FPM
    hosts: webservers
    remote_user: vagrant
    sudo: yes

how can I load ubuntu when running on production?

roles:

  • user
  • common
  • mysql-client
  • nginx
  • php-fpm

`

`

#production ec2
[webservers]
machine1.production.com
machine2.production.com

`

`

dev/stage with vagrant
[webservers]
machine1.lo
machine2.lo

[dbservers]
mysql1.lo

`

Finally is it possible, after the universal user has been added, to logout and re-connect with this user and resume the remaining tasks

Thanks

Hi,

For the variables to specify the user of each host, take a look at the documentation: http://docs.ansible.com/intro_inventory.html

ansible_ssh_user is what you are looking for.

Regarding resuming after the first step, I use a bootstrap playbook that aligns all the managed servers (you run it just once per machine) so there is no need to resume after.
If you still want the resume behavior, you can try to overwrite the variable during the playbook execution. You can take a look at the docs on how to add variables to the facts. If I recall well, it should be on the module dev section.

Br,
Tony

(attachments)

email_smslogo.png
email_icon_phone.png
email_icon_skype.png
email_icon_location.png
email_icon_email.png
email_icon_linkedin.png
email_icon_website.png