bertvv / ansible-skeleton

An opinionated skeleton for Ansible projects with a development environment powered by Vagrant.
MIT License
100 stars 32 forks source link

Configurable playbook filenames per VM #11

Closed thecodesmith closed 7 years ago

thecodesmith commented 7 years ago

I have a setup with many VMs, that fall into the categories of either "server" or "client". Perhaps there's a simpler way on the Ansible side to handle this, but I added an optional playbook: key to handle different playbook filenames.

Example:

# vagrant-hosts.yml
---
- name: ubuntu
  box: bento/ubuntu-16.04
  playbook: server.yml

- name: mac
  box: codesmith/macos-10.12.1
  playbook: client.yml

The above configuration uses ansible/server.yml and ansible/client.yml files for the Ansible provisioning. If the playbook: key is not provided, it defaults to ansible/site.yml as before.

I'm fairly new to Ansible, so if there is a cleaner way to do this, just let me know. Thanks for making this public! It's helping me immensely.

bertvv commented 7 years ago

Ooh, nice idea, I like this! Thank you for this contribution! I'm happy it's of use to you.

bertvv commented 7 years ago

Probably the "best practice" would be to define separate Ansible inventory groups for your clients and servers, but my Vagrant configuration does not support this as of yet.

Maybe I'll implement it sometime in the future (see https://www.vagrantup.com/docs/provisioning/ansible_intro.html, a bit below halfway down the page), but until then, your contribution is a fine alternative.