Skip to content

Refactor Ansible to use host_vars instead of specialised build inventory files #99

@jlqfab

Description

@jlqfab

As a natural evolution of the ansible code for Apollo we have moved from passing additional variables to playbooks to referencing those variables via inventory files. This has resulted in each host requiring a specialised inventory file for building (along with the global inventory file).

It would be advantageous to move to the use of host_vars for per-host settings. This will require per-host host_vars files (eg host_vars/apollo-001.genome.edu.au.yml) and some refactoring of playbooks and roles.

For example, this will change adding the apollo3-sandpit/apollo-001 host to the NFS server from:

ansible-playbook playbook-apollo-ubuntu-nfs-server.yml --inventory-file buildapollo3sandpit.inventory --limit nfsservervms

to something like

ansible-playbook playbook-nfs-export-for-client.yml --extra-vars "nfs_export_client=apollo-001.genome.edu.au"

with the required apollo-001 vars defined in host_vars/apollo-001.genome.edu.au.yml:

  :
nfs_export_request:
  apollo_instance_number: "001"
  nfs_apollo_user_gid=apollo_admin
  :

These variables can then be accessed from the NFS playbook with:

    - name: Load export configuration from client host_vars
      set_fact:
        apollo_instance_number: "{{ hostvars[nfs_export_client].nfs_export_request.apollo_instance_number }}"
        nfs_apollo_user_gid: "{{ hostvars[nfs_export_client].nfs_export_request.nfs_apollo_user_gid }}"
          :

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions