Running Ansible Playbook on Staging server

So I’m getting ready to move my local development to a stage server. Last time I set the stage up manually as the playbook didn’t exist back then, now I wanna use Ansible as it’s much easier obviously.

I began with spinning up a 14.04 box on DigitalOcean and installed Ansible and Git. I then created the folder www in /srv/ so that I have /srv/www/ where I cloned bedrock-ansible and my project repo so that I have them both in the same dir.

I went a head and followed the example in the notes from the bedrock repo staging example

Edit group_vars/staging

mysql_root_password: xxx

wordpress_sites:
  - site_name: sub.domain.com/project
    site_hosts:
      - sub.domain.com/project
      - x.x.x.x (my droplet ip)
    user: deploy
    group: www-data
    site_install: true
    site_title: Staging
    admin_user: admin
    admin_password: xxx
    admin_email: admin@staging.example.com
    system_cron: true
    multisite:
      enabled: false
    env:
      wp_home: http://sub.domain.com/project
      wp_siteurl: http://sub.domain.com/project/wp
      wp_env: staging
      db_name: xxx
      db_user: xxx
      db_password: xxx

Edit hosts/staging
[web]
x.x.x.x (my droplet ip)

[staging:children]
web

Run ansible-playbook -i hosts/staging site.yml
PLAY [WordPress Server: Install LEMP Stack with PHP 5.6 and MariaDB MySQL] **** 

GATHERING FACTS *************************************************************** 
fatal: [x.x.x.x] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue

TASK: [common | Update Apt] *************************************************** 
FATAL: no hosts matched or all hosts have already failed -- aborting


PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/root/site.retry

x.x.x.x               : ok=0    changed=0    unreachable=1    failed=0

So what am I doing wrong? I also tried using 127.0.0.1 but to no avail.
1 Like

Well it’s just an SSH error which means you aren’t using the correct credentials. You’ll probably need to update remote_user in site.yml to be root (or whatever you use). See https://github.com/roots/bedrock-ansible/blob/master/site.yml#L5.

sudo may need to be set to false as well.

Ah! Probably right. Will have to give it a go at work tomorrow.
But I suppose it’s bad practice to handle it with root, no? Should rather use admin (or deploy?)?

admin is the default right now because we have the secure-root.yml playbook. So yes it’s a better practice to run that first and then the normal site.yml. If you do that then it should work fine with admin.

Hm. Trying to run the secure-root.yml gives the same SSH error. Must be something else I’m doing wrong. I’m ssh’ed in to the droplet as root and try to run these cmds.

Edit: Yup. So I’m supposed to run this from my dev. Hehe, I guess I’ll take the public shaming of my not so bright actions :stuck_out_tongue: