How to automatically install Ansible Galaxy roles?

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

    I often find myself installing installing a Java JDK. Using a role makes that touch easier. I've tried a couple of different ways (including lots of .gitmodules and submodule... I have to use multiple git systems for work and all it gets ugly). My largest requirement is that I not check role code into my playbook project, mostly so I can keep everything in one place.

    The contents of my 'requirements.yml' file:

    - src: https://github.com/staylorx/ansible-role-wls-prep.git
      version: master
      name: staylorx.wls-prep
    
    - src: https://my-work-git-extravaganza.com
      version: 2.x
      name: coolplace.niftyrole
    
    #From Ansible Galaxy
    - src: staylorx.oracle-jdk
    

    I run a separate playbook, install-roles.yml:

    ---
    
    - hosts: localhost
    
      tasks:
        - file:
            path:  roles
            state: absent
    
        - local_action:
            command ansible-galaxy install -r requirements.yml --roles-path roles
    
        - lineinfile:
            dest:   .gitignore
            regexp: '^\/roles$'
            line:   '/roles'
            state:  present
    

    I run this first playbook, then I run my roles in any playbook normally. For me the secret is to ensure it's ignored by git so I don't check the roles in by mistake. Also since I wipe out the folder every time, I ensure I don't need to force or ignore errors.

提交回复
热议问题