So I am trying to wrap my head around Ansible and building a simple LEMP stack. I decided to work with a nested playbook because I want to compartmentalize as much as possib
A good solution is you have a vars.yml.dist file with examples of the variables that can be set. This exists in you repository and developers would simply make a local copy of vars.yml based on this. Then simply add the following to the your playbook:
include: vars.yml
This allows you to pass in variables to your roles, nested or not.
I imagine best practices is, if possible, to reuse existing code. If you haven't heard about it already, Ansible has Galaxy site at https://galaxy.ansible.com/ where people share various ready-to-use roles. One of such roles is mysql(its relevant github repo is at https://github.com/bennojoy/mysql.)
Not only can you utilize that role in your playbooks, but that page also has examples that show how to pass parameters/variables to your roles:
4) A fully installed/configured MySQL Server with master and slave replication.
- hosts: master
roles:
- {role: mysql, mysql_db: [{name: benz}, {name: benz2}],
mysql_users: [{name: ben3, pass: foobar, priv: "*.*:ALL"},
{name: ben2, pass: foo}],
mysql_db_id: 8 }
- hosts: slave
roles:
- {role: mysql, mysql_db: none, mysql_users: none,
mysql_repl_role: slave, mysql_repl_master: vm2,
mysql_db_id: 9, mysql_repl_user: [{name: repl, pass: foobar}] }