-
-
Notifications
You must be signed in to change notification settings - Fork 607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consolidate host files #288
Comments
Could you outline a few more benefits? |
And/or, more specifically, what problem(s) does this solve? |
Totally in for this! @nathanielks, as @fullyint said, the main benefit is that it will be easy to write cross environment scripts, like database and file sync as we were able to do with capistranowp-cli. Even this alone is enough to warrant the change IMO. Other benefits include shortened @fullyint have you looked into http://docs.vagrantup.com/v2/provisioning/ansible.html, specifically the Static Inventory section? If it work (I think we will lose the If it's impossible to have only one inventory file, would go for the symlink. Git supports it without problem, and I can't imagine an OS where symlinks wouldn't work. I would name the files |
I checked a couple of things to better understand what you wanted to do @fullyint. Here are my opinion (after research). Things I like in this:
Things i would leave like they are:
I tested the symlink locally. The concept work, but other files will need tweaking to make it functional. In the
ansible.playbook = File.join(ANSIBLE_PATH, 'dev.yml')
ansible.groups = {
'web' => ['default'],
- 'development' => ['default']
+ 'development:children' => ['web']
} @fullyint check https://github.com/louim/bedrock-ansible/commit/4b4ff3365b254eaa941c37febf3fbc673f8b5c51 to see what I had to change. Still needed to implement is the groups refactor that will be needed to use a host folder. |
@nathanielks Thank you for looking this over and helping me think it through. @louim Thank you so much for reviewing this and for explaining the benefits so well. I'll emphasize one you already mentioned. Currently, users can only access development hosts via vagrant commands, or by creating/editing host files. The proposed changes make it possible to access any host, using the default host file and Ansible commands. Abandoned ApproachesSymlinks. When I Omitting port from host file. @nathanielks and @austinpray helped me understand that if/when there is only one VM, there is no need to specify the port. An SSH connection is still possible to New Approach: Create SSH Config from
|
Closed via #313 |
Trellis could use a single host file instead of separate host files per environment. A single file may be cleaner conceptually and technically. It would also accommodate drop-in playbooks that need to access hosts from multiple environments at the same time (e.g., a playbook that syncs the db from a staging host to a production host).
Example Host File
The hosts above could translate to the host file below.
Revised Commands
ansible-playbook server.yml -e env=staging
(orenv=production
)ansible-playbook dev.yml
(see note about "Development Host File" below)Changes that Users would Face
ansible-playbook dev.yml
if desired overvagrant up
orvagrant provision
. This makes it easier to add the--tags
flag to run only portions of the playbook. (see note about "Development Host File" below)Edits to Trellis
ansible.cfg
inventory = hosts
to the[defaults]
. Thishosts
is a directory like the currenthosts
directory.hosts
directoryhosts
directory idea is revised in later comments.)hosts
directory would contain an inventory file namednon-dev
(or something). The file content would be like the example host file above.hosts
directory could contain something to make Ansible aware of the development host defined at.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
. This "something" could be a relative symlink, a copy of the vagrant host file, etc. (see note about "Development Host File" below)hosts
parameter in playbookshosts: web:&development
indev.yml
hosts: web:&{{ env }}
inserver.yml
anddeploy.yml
If a user were to run the command
ansible-playbook server.yml -e env=staging
deploy.sh
env
extra-varDevelopment Host File
A primary benefit of consolidating host files is for Ansible to be simultaneously aware of the development host and other hosts (e.g., for a playbook syncing the DB between development and staging/production). However, a challenge arises due to the fact that vagrant auto-corrects port collisions for the dev machine.
For example, after
vagrant provision
, you might see this:==> default: Fixed port collision for 22 => 2222. Now on port 2200.
This means that the development host can't be manually "hard-coded" like the staging and production hosts (if your dev host in the host file had
ansible_ssh_port=2222
, it now needsansible_ssh_port=2200
after the collision).I could use some advice on how to get the host file to pick up on this dynamic port value.
vagrant ssh-config
.)hosts/vagrant_ansible_inventory
is a symlink pointing to.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
. Presumably the symlink will work for users whose OSes handle symlinks. Windows users should be ok because they'd be running Trellis on their vagrant/ubuntu VM. But there may be perils with committing symlinks to a repo. I just don't know.hosts
directory if they want it. This option seems inferior to a symlink because theansible_ssh_port
could change, requiring re-copy.Hopefully someone out there has a better idea. I wish the main host file could use an include directive like
include = .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
Feedback Requested
Would it still be worth it if the consolidation doesn't automatically include the vagrant development host (i.e., if users have to manually create a symlink to the "Development Host File", etc.)?vagrant ssh-config
is likely superior to using a symlink.)Any better ideas than a symlink for how to simultaneously define the non-dev hosts and the dev host with its dynamicansible_ssh_port
?The text was updated successfully, but these errors were encountered: