How to automatically install Ansible Galaxy roles?

前端 未结 8 563
借酒劲吻你
借酒劲吻你 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:40

    You should use a requirements.yml file for this use-case. Describe the roles you require, using any of a variety of install methods:

    # Install a role from the Ansible Galaxy
    - src: dfarrell07.opendaylight
    
    # Install a role from GitHub
    - name: opendaylight
      src: https://github.com/dfarrell07/ansible-opendaylight
    
    # Install a role from a specific git branch
    - name: opendaylight
      src: https://github.com/dfarrell07/ansible-opendaylight
      version: origin/master
    
    # Install a role at a specific tag from GitHub
    - name: opendaylight
      src: https://github.com/dfarrell07/ansible-opendaylight
      version: 1.0.0
    
    # Install a role at a specific commit from GitHub
    - name: opendaylight
      src: https://github.com/dfarrell07/ansible-opendaylight
      version: 
    

    Then install them:

    ansible-galaxy install -r requirements.yml
    

    Here's a working example (installing OpenDaylight using Ansible as a Vagrant provisioner). See the relevant Ansible docs for more info.

提交回复
热议问题