
Ansible Galaxy에서 Github 이외의 리포지토리에서 Role 설치
2022-10-03 last update
5 minutes reading Bitbucket ansible-galaxy ansible-playbook GitLab Ansible배경
Ansible에서 Role을 재사용하려면 Ansible Galaxy에 호스팅된 Role을 설치하는 방법이 있지만, 직접 만든 리포지토리를 직접 찾아보고 설치할 수도 있습니다.
그러나 Github과 그 이외의 경우에 사용 방법에 차이가 있거나, Role의 업데이트 방법이 귀찮게 하거나, 개발중에 곤란한 일이 있었으므로, 정리했습니다.
Role 설치
Galaxy server에서 호스팅하는 역할을 사용하는 경우
ansible-galaxy install Role名
Github 리포지토리를 사용하는 경우
ansible-galaxy install Repository名
디폴트에서는 ~/.ansible/roles/이하에 인스톨 됩니다만, -p 옵션을 이용하는 것으로 배치처를 지정할 수가 있습니다.
커밋 해시와 브랜치 이름도 지정할 수 있습니다.
ansible-galaxy install -p path Repository名
Github 이외의 리포지토리를 사용하는 경우
ansible-galaxy install Git+Repository名
Github의 경우와 마찬가지로 -p를 사용할 수 있습니다.
Role 일괄 관리
requirements.yml을 작성하여 설치할 Role을 일괄 관리할 수 있습니다.
requirements.yml# from galaxy
- src: yatesr.timezone
# from GitHub
- src: https://github.com/bennojoy/nginx
# from GitHub, overriding the name and specifying a specific tag
- src: https://github.com/bennojoy/nginx
version: master
name: nginx_role
# from a webserver, where the role is packaged in a tar.gz
- src: https://some.webserver.example.com/files/master.tar.gz
name: http-role
# from Bitbucket
- src: git+http://bitbucket.org/willthames/git-ansible-galaxy
version: v1.4
# from Bitbucket, alternative syntax and caveats
- src: http://bitbucket.org/willthames/hg-ansible-galaxy
scm: hg
# from GitLab or other git-based scm
- src: [email protected]:mygroup/ansible-base.git
scm: git
version: "0.1" # quoted, so YAML doesn't parse this as a floating-point value
각 속성에 대해 설명합니다.
Galaxy server에서 호스팅하는 역할을 사용하는 경우
ansible-galaxy install Role名
Github 리포지토리를 사용하는 경우
ansible-galaxy install Repository名
디폴트에서는 ~/.ansible/roles/이하에 인스톨 됩니다만, -p 옵션을 이용하는 것으로 배치처를 지정할 수가 있습니다.
커밋 해시와 브랜치 이름도 지정할 수 있습니다.
ansible-galaxy install -p path Repository名
Github 이외의 리포지토리를 사용하는 경우
ansible-galaxy install Git+Repository名
Github의 경우와 마찬가지로 -p를 사용할 수 있습니다.
Role 일괄 관리
requirements.yml을 작성하여 설치할 Role을 일괄 관리할 수 있습니다.
requirements.yml
# from galaxy
- src: yatesr.timezone
# from GitHub
- src: https://github.com/bennojoy/nginx
# from GitHub, overriding the name and specifying a specific tag
- src: https://github.com/bennojoy/nginx
version: master
name: nginx_role
# from a webserver, where the role is packaged in a tar.gz
- src: https://some.webserver.example.com/files/master.tar.gz
name: http-role
# from Bitbucket
- src: git+http://bitbucket.org/willthames/git-ansible-galaxy
version: v1.4
# from Bitbucket, alternative syntax and caveats
- src: http://bitbucket.org/willthames/hg-ansible-galaxy
scm: hg
# from GitLab or other git-based scm
- src: [email protected]:mygroup/ansible-base.git
scm: git
version: "0.1" # quoted, so YAML doesn't parse this as a floating-point value
각 속성에 대해 설명합니다.
requirements.yml을 작성한 후 다음 명령으로 설치할 수 있습니다.
ansible-galaxy install -r requirements.yml