How to automatically install Ansible Galaxy roles?

前端 未结 8 634
借酒劲吻你
借酒劲吻你 2020-12-07 07:50

All my Ansible playbooks/roles are checked in to my git repo.

However, for Ansible Galaxy roles I always have to explicitly download them one by one on every machine

8条回答
  •  误落风尘
    2020-12-07 08:31

    You could use an Ansible role to install the needed roles using the command module.

    Here is a very basic example that runs ansible-galaxy install:

    - name: Install roles from Ansible Galaxy
      command: ansible-galaxy install {{ item.item }}
      with_items:
        - "{{ ansible_roles_list }}"
    

    The ansible_roles_list may be supplied as a variable or as a role parameter.

    If you do this in a role, it has to be applied before any other roles that you want to install using it, in a separate playbook. This is because Ansible checks the if all the roles are available before running the playbook where you reference them.

提交回复
热议问题