Provisioning a new digital ocean droplet

Ok I’m a noobie I admit it…

Been using wordpress for years on about 50 sites i own and run. I have had a look and i’m converted. Fantastic way to do stuff with wordpress… well done all at Roots - must buy you a beer sometime, if you like chatting to an oldie!

Have it all setup locally and working perfectly.

Confused at the provisioning stage. i have it all sync’d with git on bitbucket. so i know how the deploy works with the pull from git onto the new remote DO server.

What I am unsure about chaps, is the setting up the DO server. I have a base ubuntu 16.04 setup and locked down with SSH access. What in gods name do i do now?

Do i just run ansible-playbook server.yml -e env= on my local server?

After setting up all my production values in the ‘local’ production.yml?

If thats the case i’m assuming it just connects to the remote server under ssh and installs the necessary files in the right places, which is of course excellent! My confusion arises due to the necessity to install Trellis and then the bedrock site would run in a vagrant environment on the new server. I would have thought vagrant was not needed on a new server and would create an unneeded server overhead.

I do see that you can just deploy bedrock with all the necessary, but then again that suggests we need to install composer - now is that locally or again on the server.

Thanks once again and I apologise if this is all beneath the majority of you but at least let an old chap have some fun!!

1 Like

You are on the right track. When you first vagrant up, Ansible installs a bunch of stuff on the box for you. Provisioning a Digital Ocean droplet or another VM is the same thing. The droplet/VM is Ubuntu 16.04, just like the Vagrant box is. Vagrant is just using Virtualbox to create a virtual private server on your local computer, Digital Ocean is using similar technology to give you a box with your desired specs.

So yes… run the ansible playbook script, deploy, and if you follow the rest of the docs you should have your site live on the internet pretty quickly

1 Like

Many thanks for your reply.

So I’m running ansible playbook script on my local osx terminal or within the trellis vagrant on my local osx. silly question I know but I’m assuming the latter but just wanting to make sure.

You run it from your OS X terminal, Ansible is not installed on the Vagrant box (unless your’e using Windows).

Ok, it seems to have gone well - but I had one failure which is listed below. what have I missed? I have masked usernames and Ip address for obv reasons.

"The conditional check ‘site_uses_local_db and item.value.db_create |
default(True)’ failed. The error was: error while evaluating conditional
(site_uses_local_db and item.value.db_create | default(True)): {{
site_env.db_host == ‘localhost’ }}: {{ wordpress_env_defaults |
combine(item.value.env | default({}), vault_wordpress_sites[item.key].env)
}}: ‘dict object’ has no attribute u’xxx.xx.xx.xxx

The error appears to have been in ‘/Users/username/Sites/CGW/trellis/roles
/wordpress-setup/tasks/database.yml’: line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


  • name: Create database of sites
    ^ here

fatal: [xxx.xx.xx.xxx]: FAILED! => {“failed”: true}"

PLAY RECAP *********************************************************************
xxx.xx.xx.xxx : ok=89 changed=67 unreachable=0 failed=1
localhost : ok=0 changed=0 unreachable=0 failed=0

@andrew40, Have you replaced example.com with your dev url inside development/vault.yml?

4 Likes

I’ve been deploying Trellis sites for months now and I still miss this most of the time.

@andrew40 also don’t forget that you’ll need to manually import/upload your uploads and database after deploying. Here’s a quick rundown:

  1. ssh to your Vagrant box and export your database:
    $ cd trellis && vagrant ssh

  2. change directories to your web root on the Vagrant box and export your db to a dumpfile:
    $ cd /srv/www/yourdomain.com/current/
    $ wp db export

  3. exit the ssh session (type exit) and find the database dump file in your Trellis directory named something like yourdomain_com_development.sql. Upload the dump file to your DO droplet in /srv/www/yourdomain.com/current. I usually just use an (S)FTP client for this. Also while you’re there copy your uploads directory from site/web/app/ to /srv/www/yourdomain.com/shared/

  4. ssh to your DO droplet, change directories to your web root:
    $ ssh web@yourdomain.com
    $ cd /srv/www/yourdomain.com/current

  5. Trellis automatically sets up WordPress in when you deploy, but doesn’t set up your database, so reset the database and import your dumpfile:
    $ wp db reset
    $ wp db import yourdomain_com_development.sql

  6. Search and replace your development URL with your production URL:
    $wp search-replace yourdomain.dev yourdomain.com

And that’s it! Now your site is deployed and its database and uploads are copied. Remember, too, that Trellis doesn’t maintain your database or uploads in version control, so you might want to spend the extra buck or two to enable DO backups, or find some other periodic backup plan for those assets.

I hope this is helpful!

8 Likes

Yes I gathered i would have to export/import the db but this was not a deploy.

All I’m running is “ansible-playbook server.yml -e env=staging” to provision a remote server.

I haven’t run deploy yet. The error comes at the ‘Create database of sites’

yes I’ve replaced it with the ip of the DO droplet.

example.com in every vault.yml (development, staging, and production) needs to match how you edited wordpress_sites.yml.

So if you replaced example.com in wordpress_sites.yml with yourdomain.com, you’ll need make vault.yml match.

There are separate wordpress_sites.yml and vault.yml files for development, staging, and production and whatever you replaced example.com with should match in all of those places.

Yes they do, I have replaced all example.com with the ip address of the DO droplet, in both vault.yml and wordpress_sites.yml for both staging and production. In development its a local domain i.e. standard example.dev.

In all instances the vault.yml and wordpress_sites.yml match

Hope this helps…

I’ve always done this with a domain name. I’m not sure if it’ll work with an IP address. Hopefully a Roots team member can weigh in here.

Here’s hoping but have seen another similar error posted on here recently which seems related to the latest Ansible.

I am pretty sure I am doing something wrong though! :slight_smile:

I agree with @40Q and @MWDelaney that this bit of the error message …

vault_wordpress_sites[item.key].env) }}: 'dict object' has no attribute u'xxx.xx.xx.xxx'

… is an indication that this line in group_vars/staging/vault.yml doesn’t match this line in group_vars/staging/wordpress_sites.yml. Could you confirm that those exact lines match in your group_vars/staging files?

Although you can make those two lines IP addresses, I believe you’ll make your life easier if you make those lines some sort of recognizable name for the site because the name is used in file paths and logs created on the server. A name would be more identifiable and the IP address may be a little more likely to change than a name. Most people use the domain name (recommended) but you could just use cgw, like this:

# group_vars/staging/wordpress_sites.yml
wordpress_sites:
  cgw:
    site_hosts:
      - canonical: staging.cgw.com
    etc.
# group_vars/staging/vault.yml
vault_wordpress_sites:
  cgw:
    env:
      db_password: example_dbpassword
      etc.

Aside from occurring on the same task, the other error is not related. The other error message mentioned a template error, which was the root of the problem, but your error does not.


Do you have the same IP address in hosts/production as you do in hosts/staging? If so there is a slight chance this could be the cause of the error you see (but I doubt it).

It is not recommended to put the staging and production sites on the same server, so the IP should differ between hosts/production and hosts/staging.

3 Likes

Thanks for that. I was basically just taking a good look at Trellis and trying to get me through a complete process so that I could then start using it with fervour. Hence why I didn’t have a FQDN.

Here are my associated files:

# group_vars/staging/wordpress_sites.yml
wordpress_sites:
178.62.50.116:
site_hosts:
- canonical: 178.62.50.116
# redirects:
# - otherdomain.com

# group_vars/staging/vault.yml
vault_wordpress_sites:
178.62.50.116:
env:
db_password: xxxxxxxxx
etc.

I will assign a staging FQDN domain today and give it a re-run to confirm my errors…

Yes I do - I will change this today and spin up a new server.

I have actually just rewritten the files as before and provisioned the same server - ( I am assuming you can do that over a failed install) and it seems to have gone straight through with no issues.

I am assuming from that there might have been a space somewhere or something on the config files but all seems good.

I am also assuming that the 404 error not found page on Nginx at the address is because I have not deployed yet, because i would have expected to see the wordpress installation page?

1 Like