Ansible Galaxyと疎通がないとか、ローカル内でGit管理されているプライベート開発なコレクションのように、任意のGitリポジトリにあるコレクションをインストールする際のrequirements.yml
の記述例は以下の通り。
--- collections: - name: https://github.com/zaki-lknr/esxissh-ansible.git version: main type: git
指定するキーと値は以下の通り。
キー | 値 |
---|---|
name |
リポジトリURL |
version |
ブランチ名 |
type |
git を指定 |
この内容のファイルを指定することで、各種環境でコレクションをインストールできる。
(配布側) リポジトリ構成
リポジトリのルートディレクトリにgalaxy.yml
ファイルやplugins
ディレクトリなどのコレクションを構成するディレクトリとその中身を配置する。
ない場合(サブディレクトリ以下にある等)だとエラーになるので注意。
今回のサンプルコレクションはこちら。
コレクション作成の参考
(利用側) インストール
ansible-galaxy
任意のファイル名で前述の書式のファイルを作成し、以下コマンドを実行。
お作法的には collections/requirements.yml
が好ましい。多分。
$ ansible-galaxy install -r collections/requirements.yml
インストール先ディレクトリはデフォルトでは~/.ansible
以下。
変更したい場合はansible.cfg
などでインストール先を指定する。
[defaults] collections_path = /path/to/ansible/collections
ansible-builder
execution-environment.yml
のdependencies
に指定するrequirements.yml
でインストール内容を記述して、あとは普通にビルドする。
$ ansible-builder build -t esxi-ssh:latest -v 3 Ansible Builder is building your execution environment image, "esxi-ssh:latest". File context/_build/requirements.yml is already up-to-date. File context/_build/requirements.txt is already up-to-date. File context/_build/bindep.txt is already up-to-date. File context/_build/ansible.cfg is already up-to-date. : : [1/3] STEP 8/8: RUN ansible-galaxy collection install $ANSIBLE_GALAXY_CLI_COLLECTION_OPTS -r requirements.yml --collections-path /usr/share/ansible/collections Starting galaxy collection install process Process install dependency map Cloning into '/home/runner/.ansible/tmp/ansible-local-116wclers/tmptw5tpno2/esxissh-ansible347k3r33'... Already on 'main' Your branch is up to date with 'origin/main'. Starting collection install process Installing 'zaki_lknr.esxissh:1.1.0' to '/usr/share/ansible/collections/ansible_collections/zaki_lknr/esxissh' Created collection for zaki_lknr.esxissh:1.1.0 at /usr/share/ansible/collections/ansible_collections/zaki_lknr/esxissh zaki_lknr.esxissh:1.1.0 was installed successfully --> 304eaaf07f6 : :
AAP / AWX / Tower
(確認はAAP 2.1のみ実施)
リポジトリの collections/requirements.yml
にインストールしたいコレクションを記述する。
サンプルとしては以下。
これでソースコントロールの更新時にコレクションがインストールされる。
参考
ドキュメントは以下、Install multiple collections with a requirements fileより。
また、Git上にあるRoleのインストール関連は以下。