Ansible best practice for passing vars to nested playbooks?

后端 未结 2 1031
灰色年华
灰色年华 2021-01-20 06:11

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

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-20 06:39

    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}] }
    

提交回复
热议问题