| 1 |
name: CI |
| 2 |
on: |
| 3 |
pull_request: |
| 4 |
schedule: |
| 5 |
- cron: "0 3 * * *" |
| 6 |
|
| 7 |
jobs: |
| 8 |
mongodb-cache: |
| 9 |
runs-on: ubuntu-24.04 |
| 10 |
defaults: |
| 11 |
run: |
| 12 |
working-directory: ansible_collections/community/mongodb |
| 13 |
env: |
| 14 |
ANSIBLE_CACHE_PLUGIN: "community.mongodb.mongodb" |
| 15 |
ANSIBLE_CACHE_PLUGIN_CONNECTION: "mongodb://mongoadmin:secret@localhost:27017/cache?authSource=admin" |
| 16 |
ANSIBLE_CACHE_PLUGIN_TIMEOUT: 0 |
| 17 |
strategy: |
| 18 |
matrix: |
| 19 |
versions: |
| 20 |
- ansible_version: "stable-2.15" |
| 21 |
python_version: "3.11" |
| 22 |
- ansible_version: "stable-2.16" |
| 23 |
python_version: "3.11" |
| 24 |
- ansible_version: "stable-2.19" |
| 25 |
python_version: "3.12" |
| 26 |
- ansible_version: "devel" |
| 27 |
python_version: "3.12" |
| 28 |
- ansible_version: "devel" |
| 29 |
python_version: "3.13" |
| 30 |
|
| 31 |
steps: |
| 32 |
|
| 33 |
- name: Check out code |
| 34 |
uses: actions/checkout@v4 |
| 35 |
with: |
| 36 |
path: ansible_collections/community/mongodb |
| 37 |
|
| 38 |
- name: Set up Python ${{ matrix.versions.python_version }} |
| 39 |
uses: actions/setup-python@v5 |
| 40 |
with: |
| 41 |
python-version: ${{ matrix.versions.python_version }} |
| 42 |
|
| 43 |
- name: Install ansible-base (${{ matrix.versions.ansible_version }}) |
| 44 |
uses: nick-invision/retry@v3 |
| 45 |
with: |
| 46 |
timeout_minutes: 3 |
| 47 |
max_attempts: 3 |
| 48 |
command: pip install https://github.com/ansible/ansible/archive/${{ matrix.versions.ansible_version }}.tar.gz --disable-pip-version-check |
| 49 |
|
| 50 |
- name: Build the collection |
| 51 |
run: ansible-galaxy collection build |
| 52 |
|
| 53 |
- name: Rename the build artifact |
| 54 |
run: mv community-mongodb-*.tar.gz community-mongodb-latest.tar.gz |
| 55 |
|
| 56 |
- name: Install collection |
| 57 |
run: ansible-galaxy collection install community-mongodb-*.tar.gz |
| 58 |
|
| 59 |
- name: Create docker volume |
| 60 |
run: docker volume create mongocache |
| 61 |
|
| 62 |
- name: Run the mongodb cache inside a docker container |
| 63 |
run: |
| 64 |
docker run -d --name mongocache -e MONGO_INITDB_ROOT_USERNAME=mongoadmin |
| 65 |
-e MONGO_INITDB_ROOT_PASSWORD=secret -p 27017:27017 |
| 66 |
-v mongocache:/data/db mongo:latest |
| 67 |
|
| 68 |
- name: Install mongodb-mongosh |
| 69 |
uses: nick-invision/retry@v3 |
| 70 |
with: |
| 71 |
timeout_minutes: 3 |
| 72 |
max_attempts: 3 |
| 73 |
command: | |
| 74 |
sudo apt-get install gnupg curl |
| 75 |
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \ |
| 76 |
sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor |
| 77 |
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list |
| 78 |
sudo apt-get update |
| 79 |
sudo apt-get install mongodb-mongosh |
| 80 |
|
| 81 |
# https://github.community/t/set-output-truncates-multiline-strings/16852/5 |
| 82 |
- name: Run ansible without pymongo installed to generate the warning |
| 83 |
id: no-pymongo |
| 84 |
run: | |
| 85 |
output=$(ansible localhost -m setup 2>&1) |
| 86 |
echo "$output" |
| 87 |
output="${output//'%'/'%25'}" |
| 88 |
output="${output//$'\n'/'%0A'}" |
| 89 |
output="${output//$'\r'/'%0D'}" |
| 90 |
echo "nopymongo=$output" >> $GITHUB_OUTPUT |
| 91 |
|
| 92 |
- name: Test cache handling of missing pymongo |
| 93 |
uses: nick-invision/assert-action@v2 |
| 94 |
with: |
| 95 |
expected: "The 'pymongo' python module is required for the mongodb fact cache" |
| 96 |
actual: ${{ steps.no-pymongo.outputs.nopymongo }} |
| 97 |
comparison: contains |
| 98 |
|
| 99 |
- name: Install pymongo |
| 100 |
uses: nick-invision/retry@v3 |
| 101 |
with: |
| 102 |
timeout_minutes: 3 |
| 103 |
max_attempts: 3 |
| 104 |
command: pip install pymongo |
| 105 |
|
| 106 |
- name: Run ansible to generate the mongodb cache |
| 107 |
run: ansible localhost -m setup |
| 108 |
|
| 109 |
- name: Query mongo to see what we have in the cache |
| 110 |
id: mongo1 |
| 111 |
run: | |
| 112 |
output=$(mongosh cache --authenticationDatabase admin -u mongoadmin -p secret --eval "db.cache.find()") |
| 113 |
echo "$output" |
| 114 |
output="${output//'%'/'%25'}" |
| 115 |
output="${output//$'\n'/'%0A'}" |
| 116 |
output="${output//$'\r'/'%0D'}" |
| 117 |
echo "mongo=$output" >> $GITHUB_OUTPUT |
| 118 |
|
| 119 |
- name: Test that we have something that looks like a cache record |
| 120 |
uses: nick-invision/assert-action@v2 |
| 121 |
with: |
| 122 |
expected: ansible_processor_count |
| 123 |
actual: ${{ steps.mongo1.outputs.mongo }} |
| 124 |
comparison: contains |
| 125 |
|
| 126 |
- name: Collection should not have a ttl index |
| 127 |
id: mongo2 |
| 128 |
run: | |
| 129 |
output=$(mongosh cache --authenticationDatabase admin -u mongoadmin -p secret --eval "db.cache.getIndexes()") |
| 130 |
echo "$output" |
| 131 |
output="${output//'%'/'%25'}" |
| 132 |
output="${output//$'\n'/'%0A'}" |
| 133 |
output="${output//$'\r'/'%0D'}" |
| 134 |
echo "mongo=$output" >> $GITHUB_OUTPUT |
| 135 |
|
| 136 |
- name: Test that we don't have an index called ttl |
| 137 |
uses: nick-invision/assert-action@v2 |
| 138 |
with: |
| 139 |
expected: ttl |
| 140 |
actual: ${{ steps.mongo2.outputs.mongo }} |
| 141 |
comparison: notContains |
| 142 |
|
| 143 |
- name: Test that we have good output from getindexes |
| 144 |
uses: nick-invision/assert-action@v2 |
| 145 |
with: |
| 146 |
expected: "_id_" |
| 147 |
actual: ${{ steps.mongo2.outputs.mongo }} |
| 148 |
comparison: contains |
| 149 |
|
| 150 |
- name: Repeat the action to hit the cache again |
| 151 |
run: ansible localhost -m setup |
| 152 |
|
| 153 |
- name: Query mongo to see what we have in the cache |
| 154 |
id: mongo3 |
| 155 |
run: | |
| 156 |
output=$(mongosh cache --authenticationDatabase admin -u mongoadmin -p secret --eval "db.cache.find()") |
| 157 |
echo "$output" |
| 158 |
output="${output//'%'/'%25'}" |
| 159 |
output="${output//$'\n'/'%0A'}" |
| 160 |
output="${output//$'\r'/'%0D'}" |
| 161 |
echo "mongo=$output" >> $GITHUB_OUTPUT |
| 162 |
|
| 163 |
- name: Test that we have something that looks like a cache record |
| 164 |
uses: nick-invision/assert-action@v2 |
| 165 |
with: |
| 166 |
expected: ansible_processor_count |
| 167 |
actual: ${{ steps.mongo3.outputs.mongo }} |
| 168 |
comparison: contains |
| 169 |
|
| 170 |
- name: Collection should not have a ttl index |
| 171 |
id: mongo4 |
| 172 |
run: | |
| 173 |
output=$(mongosh cache --authenticationDatabase admin -u mongoadmin -p secret --eval "db.cache.getIndexes()") |
| 174 |
echo "$output" |
| 175 |
output="${output//'%'/'%25'}" |
| 176 |
output="${output//$'\n'/'%0A'}" |
| 177 |
output="${output//$'\r'/'%0D'}" |
| 178 |
echo "mongo=$output" >> $GITHUB_OUTPUT |
| 179 |
|
| 180 |
- name: Test that we don't have an index called ttl |
| 181 |
uses: nick-invision/assert-action@v2 |
| 182 |
with: |
| 183 |
expected: ttl |
| 184 |
actual: ${{ steps.mongo4.outputs.mongo }} |
| 185 |
comparison: notContains |
| 186 |
|
| 187 |
- name: Test that we have good output from getindexes |
| 188 |
uses: nick-invision/assert-action@v2 |
| 189 |
with: |
| 190 |
expected: "_id_" |
| 191 |
actual: ${{ steps.mongo4.outputs.mongo }} |
| 192 |
comparison: contains |
| 193 |
|
| 194 |
- name: Run the action again with a modified timeout |
| 195 |
env: |
| 196 |
ANSIBLE_CACHE_PLUGIN_TIMEOUT: 3600 |
| 197 |
run: ansible localhost -m setup |
| 198 |
|
| 199 |
- name: Query mongo to see what we have in the cache |
| 200 |
id: mongo5 |
| 201 |
run: | |
| 202 |
output=$(mongosh cache --authenticationDatabase admin -u mongoadmin -p secret --eval "db.cache.find()") |
| 203 |
echo "$output" |
| 204 |
output="${output//'%'/'%25'}" |
| 205 |
output="${output//$'\n'/'%0A'}" |
| 206 |
output="${output//$'\r'/'%0D'}" |
| 207 |
echo "mongo=$output" >> $GITHUB_OUTPUT |
| 208 |
|
| 209 |
- name: Test that we have something that looks like a cache record |
| 210 |
uses: nick-invision/assert-action@v2 |
| 211 |
with: |
| 212 |
expected: ansible_processor_count |
| 213 |
actual: ${{ steps.mongo5.outputs.mongo }} |
| 214 |
comparison: contains |
| 215 |
|
| 216 |
- name: Collection should have a ttl index |
| 217 |
id: mongo6 |
| 218 |
run: | |
| 219 |
output=$(mongosh cache --authenticationDatabase admin -u mongoadmin -p secret --eval "db.cache.getIndexes()") |
| 220 |
echo "$output" |
| 221 |
output="${output//'%'/'%25'}" |
| 222 |
output="${output//$'\n'/'%0A'}" |
| 223 |
output="${output//$'\r'/'%0D'}" |
| 224 |
echo "mongo=$output" >> $GITHUB_OUTPUT |
| 225 |
|
| 226 |
- name: Test that we do have an index called ttl |
| 227 |
uses: nick-invision/assert-action@v2 |
| 228 |
with: |
| 229 |
expected: ttl |
| 230 |
actual: ${{ steps.mongo6.outputs.mongo }} |
| 231 |
comparison: contains |
| 232 |
|
| 233 |
- name: Repeat the action |
| 234 |
env: |
| 235 |
ANSIBLE_CACHE_PLUGIN_TIMEOUT: 3600 |
| 236 |
run: ansible localhost -m setup |
| 237 |
|
| 238 |
- name: Query mongo to see what we have in the cache |
| 239 |
id: mongo7 |
| 240 |
run: | |
| 241 |
output=$(mongosh cache --authenticationDatabase admin -u mongoadmin -p secret --eval "db.cache.find()") |
| 242 |
echo "$output" |
| 243 |
output="${output//'%'/'%25'}" |
| 244 |
output="${output//$'\n'/'%0A'}" |
| 245 |
output="${output//$'\r'/'%0D'}" |
| 246 |
echo "mongo=$output" >> $GITHUB_OUTPUT |
| 247 |
|
| 248 |
- name: Test that we have something that looks like a cache record |
| 249 |
uses: nick-invision/assert-action@v2 |
| 250 |
with: |
| 251 |
expected: ansible_processor_count |
| 252 |
actual: ${{ steps.mongo7.outputs.mongo }} |
| 253 |
comparison: contains |
| 254 |
|
| 255 |
- name: Collection should have a ttl index |
| 256 |
id: mongo8 |
| 257 |
run: | |
| 258 |
output=$(mongosh cache --authenticationDatabase admin -u mongoadmin -p secret --eval "db.cache.getIndexes()") |
| 259 |
echo "$output" |
| 260 |
output="${output//'%'/'%25'}" |
| 261 |
output="${output//$'\n'/'%0A'}" |
| 262 |
output="${output//$'\r'/'%0D'}" |
| 263 |
echo "mongo=$output" >> $GITHUB_OUTPUT |
| 264 |
|
| 265 |
- name: Test that we do have an index called ttl |
| 266 |
uses: nick-invision/assert-action@v2 |
| 267 |
with: |
| 268 |
expected: ttl |
| 269 |
actual: ${{ steps.mongo8.outputs.mongo }} |
| 270 |
comparison: contains |
| 271 |
|
| 272 |
- name: Set timeout back to zero |
| 273 |
env: |
| 274 |
ANSIBLE_CACHE_PLUGIN_TIMEOUT: 0 |
| 275 |
run: ansible localhost -m setup |
| 276 |
|
| 277 |
- name: Query mongo to see what we have in the cache |
| 278 |
id: mongo9 |
| 279 |
run: | |
| 280 |
output=$(mongosh cache --authenticationDatabase admin -u mongoadmin -p secret --eval "db.cache.find()") |
| 281 |
echo "$output" |
| 282 |
output="${output//'%'/'%25'}" |
| 283 |
output="${output//$'\n'/'%0A'}" |
| 284 |
output="${output//$'\r'/'%0D'}" |
| 285 |
echo "mongo=$output" >> $GITHUB_OUTPUT |
| 286 |
|
| 287 |
- name: Test that we have something that looks like a cache record |
| 288 |
uses: nick-invision/assert-action@v2 |
| 289 |
with: |
| 290 |
expected: ansible_processor_count |
| 291 |
actual: ${{ steps.mongo9.outputs.mongo }} |
| 292 |
comparison: contains |
| 293 |
|
| 294 |
- name: Collection should not have a ttl index |
| 295 |
id: mongo10 |
| 296 |
run: | |
| 297 |
output=$(mongosh cache --authenticationDatabase admin -u mongoadmin -p secret --eval "db.cache.getIndexes()") |
| 298 |
echo "$output" |
| 299 |
output="${output//'%'/'%25'}" |
| 300 |
output="${output//$'\n'/'%0A'}" |
| 301 |
output="${output//$'\r'/'%0D'}" |
| 302 |
echo "mongo=$output" >> $GITHUB_OUTPUT |
| 303 |
|
| 304 |
- name: Test that we don't have an index called ttl |
| 305 |
uses: nick-invision/assert-action@v2 |
| 306 |
with: |
| 307 |
expected: ttl |
| 308 |
actual: ${{ steps.mongo10.outputs.mongo }} |
| 309 |
comparison: notContains |
| 310 |
|
| 311 |
- name: Test that we have good output from getindexes |
| 312 |
uses: nick-invision/assert-action@v2 |
| 313 |
with: |
| 314 |
expected: "_id_" |
| 315 |
actual: ${{ steps.mongo10.outputs.mongo }} |
| 316 |
comparison: contains |