Just about to add a subdomain to an existing trellis setup with a TLQDN. So I adjusted wordpress_sites.yml for development and production:
members.domain.com:
site_hosts:
- canonical: members.domain.com
local_path: ../members # path targeting local Bedrock site directory (relative to Ansible root)
repo: git@github.com:jasperf/domain.git # replace with your Git repo URL
repo_subtree_path: members # relative path to your Bedrock/WP directory in your repo
branch: master
multisite:
enabled: false
ssl:
enabled: true
provider: letsencrypt
cache:
enabled: true
as well as the vault files for both environments. I am not using staging.
Now I was wondering. What about the hosts/production file? I now have
# Add each host to the [production] group and to a "type" group such as [web] or [db].
# List each machine only once per [group], even if it will host multiple sites.
[production]
mysite.com
[web]
mysite.com
And the new subdomain will be on the same Droplet / ip address. Should I add members.domain.com here for production and web or should I just replace the domain by the ip address maybe?
Saw at To deploy a second site that I should just the ip. for under production. But not sure if I should keep the domain under [web]
In the end it was ip address for both:
# Add each host to the [production] group and to a "type" group such as [web] or [db].
# List each machine only once per [group], even if it will host multiple sites.
[production]
xxx.xxx.xxx.xxx
[web]
xxx.xxx.xxx.xxx
That worked. Had to fix the local .env as well as I forgot but that was only a local development issue.
This is the hostname Ansible will use in making its SSH connection to your server (e.g., ssh root@mysite.com
or ssh root@12.34.56.78
). You could keep mysite.com
, switch to members.domain.com
, or use the IP.
Whatever hostname you use, be consistent between the [production]
and [web]
groups so that the Ansible host pattern will find a host from hosts/production
that is in both the web
and production
groups.
Given that each Ansible task output shows the hostname, if you have multiple sites on the server, you might prefer tasks to show a generic hostname like IP. Or you could create and use a hostname alias which will appear in task output:
# hosts/production
my_production_hostname ansible_host=12.34.56.78
[production]
my_production_hostname
[web]
my_production_hostname
If you keep mysite.com
, the slight disadvantage is that you may be running the server.yml playbook with the other site in mind, but the output shows mysite.com
. Not a big deal. Another disadvantage is for new sites/domains when DNS is not already set up; you’d have to put a temporary entry in your /etc/hosts
file to fake DNS (not necessary when you just use IP in hosts/production
).
The advantage of keeping mysite.com
is that you do not have to indicate the IP, assuming you have public DNS set up. The implication is that if your mysite.com
IP changes and you have updated DNS, you don’t have to do anything in your hosts/production
file. This would be best for sites/servers whose IPs end up changing often.
2 Likes
Did not know about the host alias function. That is a great option. And thanks for the general explanation. As I will keep my Droplet’s ip address and do not intend to change it for quite some time, the using of an ip address sounds like a great solution.
1 Like