Skip to content

Commit 600ad68

Browse files
committed
update molecule to use ghcr.io or mirror.gcr.io for container pull
1 parent 32e22c9 commit 600ad68

File tree

16 files changed

+177
-48
lines changed

16 files changed

+177
-48
lines changed

hooks/molecule.rc

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,137 @@ vercomp() {
3737
fi
3838
if ((10#${ver1[i]} < 10#${ver2[i]}))
3939
then
40+
COLLECTION_DIR="${HOME}/.ansible/collections/ansible_collections/${COLLECTION_NAMESPACE}/${COLLECTION_NAME}"
41+
42+
TOX_ARGS=
43+
44+
if [ -n "${TOX_SCENARIO}" ]
45+
then
46+
TOX_ARGS="--scenario-name ${TOX_SCENARIO}"
47+
fi
48+
49+
TOX_OPTS="-e ${TOX_ANSIBLE}"
50+
51+
vercomp() {
52+
53+
[[ $1 == $2 ]] && return 0
54+
v1=$(echo "$1" | sed -e 's|-|.|g')
55+
v2=$(echo "$2" | sed -e 's|-|.|g')
56+
57+
local IFS=.
58+
local i ver1=($1) ver2=($2)
59+
# fill empty fields in ver1 with zeros
60+
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
61+
do
62+
ver1[i]=0
63+
done
64+
65+
for ((i=0; i<${#ver1[@]}; i++))
66+
do
67+
if [[ -z ${ver2[i]} ]]
68+
then
69+
# fill empty fields in ver2 with zeros
70+
ver2[i]=0
71+
fi
72+
if ((10#${ver1[i]} > 10#${ver2[i]}))
73+
then
74+
return 1
75+
fi
76+
if ((10#${ver1[i]} < 10#${ver2[i]}))
77+
then
78+
return 2
79+
fi
80+
done
81+
return 0
82+
}
83+
84+
list_collections() {
85+
86+
if [ -f collections.yml ]
87+
then
88+
echo "required collection(s)"
89+
90+
collections=$(ansible-galaxy collection list --format json | grep -v -E "starting run|Validate TLS")
91+
92+
is_installed="false"
93+
94+
for collection in $(grep -v "#" collections.yml | grep "^ - name: " | awk -F ': ' '{print $2}')
95+
do
96+
required_version="$(grep -v "#" collections.yml | grep -A1 "^ - name: ${collection}" | grep "version: " 2> /dev/null | awk -F ': ' '{print $2}' | sed -e 's|=||' -e 's|>||' -e 's|"||g')"
97+
98+
while read repository
99+
do
100+
version=
101+
installed_version=
102+
required_version=
103+
104+
REPOSITORY=${repository}
105+
COLLECTION=${collection}
106+
107+
repo=$(echo ${collections} | \
108+
jq -r \
109+
--arg REPOSITORY "$REPOSITORY" \
110+
'to_entries | map(select(.key == $REPOSITORY)) | from_entries')
111+
112+
# echo "$repo"
113+
114+
installed_version=$(echo ${repo} | \
115+
jq -r \
116+
--arg COLLECTION "$COLLECTION" \
117+
'.[] | with_entries(select(.key | contains($COLLECTION))) | select(.key != {}) | .[].version')
118+
119+
if [[ ! -z "${installed_version}" ]]
120+
then
121+
echo " - '${collection}' is installed in version ${installed_version} (in ${repository})."
122+
fi
123+
done < <(echo "${collections}" | jq -r 'keys[]')
124+
done
125+
fi
126+
}
127+
128+
ansible_collection() {
129+
130+
if [ -f collections.yml ]
131+
then
132+
list_collections
133+
134+
# force install of all collections
135+
ansible-galaxy collection install --force --requirements-file collections.yml > /dev/null
136+
fi
137+
}
138+
139+
install_collection() {
140+
local collection="${1}"
141+
142+
echo "Install the required collection '${collection}'"
143+
ansible-galaxy collection install ${collection} > /dev/null
144+
}
145+
146+
remove_collection() {
147+
148+
local collection="${1}"
149+
150+
namespace="$(echo "${collection}" | cut -d '.' -f1)"
151+
name="$(echo "${collection}" | cut -d '.' -f2)"
152+
153+
collection="${HOME}/.ansible/collections/ansible_collections/${namespace}/${name}"
154+
155+
rm \
156+
--recursive \
157+
--force \
158+
"${collection}" > /dev/null
159+
}
160+
161+
publish() {
162+
163+
TOKEN="${HOME}/.ansible/galaxy_token"
164+
165+
if [ -e "${TOKEN}" ]
166+
then
167+
ansible-galaxy import --token=$(cat "${TOKEN}") bodsch # "???"
168+
fi
169+
}
170+
40171
return 2
41172
fi
42173
done

hooks/run_tox.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
TOX_TEST="${1}"
99

10-
11-
1210
if [[ ! -z "${COLLECTION_ROLE// }" ]]
1311
then
1412
if [ -d "roles/${COLLECTION_ROLE}" ]

roles/icinga2/molecule/default/molecule.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ driver:
77

88
platforms:
99
- name: database
10-
image: "bodsch/ansible-debian:12"
10+
image: "ghcr.io/bodsch/docker-ansible/ansible-debian:12"
1111
command: ${MOLECULE_DOCKER_COMMAND:-""}
1212
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
1313
privileged: true
@@ -29,7 +29,7 @@ platforms:
2929
ipv4_address: "10.11.0.10"
3030

3131
- name: instance
32-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
32+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
3333
command: ${MOLECULE_DOCKER_COMMAND:-""}
3434
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
3535
privileged: true

roles/icinga2/molecule/icinga2-with-icingadb/molecule.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ driver:
77

88
platforms:
99
- name: database
10-
image: "bodsch/ansible-debian:12"
10+
image: "ghcr.io/bodsch/docker-ansible/ansible-debian:12"
1111
command: ${MOLECULE_DOCKER_COMMAND:-""}
1212
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
1313
privileged: true
@@ -31,7 +31,7 @@ platforms:
3131
ipv4_address: "10.13.0.10"
3232

3333
- name: icingadb
34-
image: "bodsch/ansible-debian:12"
34+
image: "ghcr.io/bodsch/docker-ansible/ansible-debian:12"
3535
command: ${MOLECULE_DOCKER_COMMAND:-""}
3636
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
3737
privileged: true
@@ -50,7 +50,7 @@ platforms:
5050
ipv4_address: "10.13.0.11"
5151

5252
- name: instance
53-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
53+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
5454
command: ${MOLECULE_DOCKER_COMMAND:-""}
5555
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
5656
privileged: true

roles/icinga2/molecule/icinga2-with-influxdb/molecule.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ driver:
77

88
platforms:
99
- name: database
10-
image: "bodsch/ansible-debian:12"
10+
image: "ghcr.io/bodsch/docker-ansible/ansible-debian:12"
1111
command: ${MOLECULE_DOCKER_COMMAND:-""}
1212
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
1313
privileged: true
@@ -29,7 +29,7 @@ platforms:
2929
ipv4_address: "10.14.0.10"
3030

3131
- name: influxdb
32-
image: "bodsch/ansible-debian:12"
32+
image: "ghcr.io/bodsch/docker-ansible/ansible-debian:12"
3333
command: ${MOLECULE_DOCKER_COMMAND:-""}
3434
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
3535
privileged: true
@@ -46,7 +46,7 @@ platforms:
4646
ipv4_address: "10.14.0.11"
4747

4848
- name: instance
49-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
49+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
5050
command: ${MOLECULE_DOCKER_COMMAND:-""}
5151
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
5252
privileged: true

roles/icinga2/molecule/primary-as-ha/molecule.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ driver:
77

88
platforms:
99
- name: database
10-
image: "bodsch/ansible-debian:12"
10+
image: "ghcr.io/bodsch/docker-ansible/ansible-debian:12"
1111
command: ${MOLECULE_DOCKER_COMMAND:-""}
1212
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
1313
privileged: true
@@ -29,7 +29,7 @@ platforms:
2929
ipv4_address: "10.15.0.10"
3030

3131
- name: primary1
32-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
32+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
3333
command: ${MOLECULE_DOCKER_COMMAND:-""}
3434
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
3535
privileged: true
@@ -49,7 +49,7 @@ platforms:
4949
ipv4_address: "10.15.0.21"
5050

5151
- name: primary2
52-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
52+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
5353
command: ${MOLECULE_DOCKER_COMMAND:-""}
5454
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
5555
privileged: true
@@ -69,7 +69,7 @@ platforms:
6969
ipv4_address: "10.15.0.22"
7070

7171
- name: satellite
72-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
72+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
7373
command: ${MOLECULE_DOCKER_COMMAND:-""}
7474
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
7575
privileged: true

roles/icinga2/molecule/primary-with-satellite/molecule.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ lint: |
1313
1414
platforms:
1515
- name: database
16-
image: "bodsch/ansible-debian:12"
16+
image: "ghcr.io/bodsch/docker-ansible/ansible-debian:12"
1717
command: ${MOLECULE_DOCKER_COMMAND:-""}
1818
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
1919
privileged: true
@@ -35,7 +35,7 @@ platforms:
3535
ipv4_address: "10.16.0.10"
3636

3737
- name: instance
38-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
38+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
3939
command: ${MOLECULE_DOCKER_COMMAND:-""}
4040
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
4141
privileged: true
@@ -55,7 +55,7 @@ platforms:
5555
ipv4_address: "10.16.0.20"
5656

5757
- name: satellite
58-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
58+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
5959
command: ${MOLECULE_DOCKER_COMMAND:-""}
6060
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
6161
privileged: true

roles/icinga2/molecule/primary-with-satellites/molecule.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ driver:
1212

1313
platforms:
1414
- name: database
15-
image: "bodsch/ansible-debian:12"
15+
image: "ghcr.io/bodsch/docker-ansible/ansible-debian:12"
1616
command: ${MOLECULE_DOCKER_COMMAND:-""}
1717
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
1818
privileged: true
@@ -34,7 +34,7 @@ platforms:
3434
ipv4_address: "10.17.0.10"
3535

3636
- name: instance
37-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
37+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
3838
command: ${MOLECULE_DOCKER_COMMAND:-""}
3939
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
4040
privileged: true
@@ -54,7 +54,7 @@ platforms:
5454
ipv4_address: "10.17.0.20"
5555

5656
- name: satellite-01
57-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
57+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
5858
command: ${MOLECULE_DOCKER_COMMAND:-""}
5959
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
6060
privileged: true
@@ -74,7 +74,7 @@ platforms:
7474
ipv4_address: "10.17.0.31"
7575

7676
- name: satellite-02
77-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
77+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
7878
command: ${MOLECULE_DOCKER_COMMAND:-""}
7979
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
8080
privileged: true
@@ -94,7 +94,7 @@ platforms:
9494
ipv4_address: "10.17.0.32"
9595

9696
- name: satellite-03
97-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
97+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
9898
command: ${MOLECULE_DOCKER_COMMAND:-""}
9999
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
100100
privileged: true
@@ -114,7 +114,7 @@ platforms:
114114
ipv4_address: "10.17.0.33"
115115

116116
- name: satellite-04
117-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
117+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
118118
command: ${MOLECULE_DOCKER_COMMAND:-""}
119119
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
120120
privileged: true
@@ -134,7 +134,7 @@ platforms:
134134
ipv4_address: "10.17.0.34"
135135

136136
- name: satellite-05
137-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
137+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
138138
command: ${MOLECULE_DOCKER_COMMAND:-""}
139139
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
140140
privileged: true

roles/icingadb/molecule/default/molecule.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ driver:
77

88
platforms:
99
- name: database
10-
image: "bodsch/ansible-debian:12"
10+
image: "ghcr.io/bodsch/docker-ansible/ansible-debian:12"
1111
command: ${MOLECULE_DOCKER_COMMAND:-""}
1212
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
1313
privileged: true
@@ -30,7 +30,7 @@ platforms:
3030
ipv4_address: "10.13.0.10"
3131

3232
- name: instance
33-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
33+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
3434
command: ${MOLECULE_DOCKER_COMMAND:-""}
3535
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
3636
privileged: true

roles/icingaweb2/molecule/default/molecule.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ driver:
77

88
platforms:
99
- name: database
10-
image: "bodsch/ansible-debian:12"
10+
image: "ghcr.io/bodsch/docker-ansible/ansible-debian:12"
1111
command: ${MOLECULE_DOCKER_COMMAND:-""}
1212
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
1313
privileged: true
@@ -31,7 +31,7 @@ platforms:
3131
ipv4_address: "10.11.0.1"
3232

3333
# - name: icinga2
34-
# image: "bodsch/ansible-debian:12"
34+
# image: "ghcr.io/bodsch/docker-ansible/ansible-debian:12"
3535
# command: ${MOLECULE_DOCKER_COMMAND:-""}
3636
# docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
3737
# privileged: true
@@ -45,7 +45,7 @@ platforms:
4545
# ipv4_address: "10.11.0.2"
4646

4747
- name: instance
48-
image: "bodsch/ansible-${DISTRIBUTION:-debian:12}"
48+
image: "ghcr.io/bodsch/docker-ansible/ansible-${DISTRIBUTION:-debian:12}"
4949
command: ${MOLECULE_DOCKER_COMMAND:-""}
5050
docker_host: "${DOCKER_HOST:-unix://run/docker.sock}"
5151
privileged: true

0 commit comments

Comments
 (0)