gcp_compute_snapshot usually doesn't work with a registered gcp_compute_disk_info disk
SUMMARY
when gcp_compute_disk_info is used to obtain a source disk and then given to gcp_compute_snapshot, the snapshot usually fails with:
"msg": "GCP returned error: {'error': {'code': 400, 'message': "Invalid value for field 'disk': 'None'. Must be a match of regex 'a-z?|[1-9][0-9]{0,19}'", 'errors': [{'message': "Invalid value for field 'disk': 'None'. Must be a match of regex 'a-z?|[1-9][0-9]{0,19}'", 'domain': 'global', 'reason': 'invalid'}]}}"
it seems to only work if supplied using name dictionary instead of the registered variable. This contradicts the documentation:
A reference to the disk used to create this snapshot. This field represents a link to a Disk resource in GCP. It can be specified in two ways. First, you can place a dictionary with key 'name' and value of your resource's name Alternatively, you can add
register: name-of-resourceto a gcp_compute_disk task and then set this source_disk field to "{{name-of-resource }}"
The second way usually does not work. Note that it sometimes worked during testing, about 1/10 times it would work. I can't explain this, but providing the name dict only (first method from docs) seemed to work every time.
ISSUE TYPE
- Bug Report
COMPONENT NAME
gcp_compute_snapshot
ANSIBLE VERSION
ansible 2.10.7
config file = /home/scott/src/setup/.ansible.cfg
configured module search path = ['/home/scott/src/setup/lib']
ansible python module location = /home/scott/src/setup/venv/lib/python3.8/site-packages/ansible
executable location = /home/scott/src/setup/venv/bin/ansible
python version = 3.8.8 (tags/v3.8.8:024d8058b0, Mar 2 2021, 18:15:50) [GCC 9.3.0]
CONFIGURATION
stock
OS / ENVIRONMENT
linux
STEPS TO REPRODUCE
# ...
- gcp_compute_disk_info:
filters: ['name={{diskdev}}']
# ...
register: srcdisk
- name: snapshot_dev_disk
gcp_compute_snapshot:
name: '{{snapname}}'
source_disk: '{{srcdisk}}'
# ...
register: snapdisk
# ...
gcp_compute_disk_info returns a list of matched disks, in your case it will have only one element, so I guess changing the gcp_compute_snapshot task to below can help:
- name: snapshot_dev_disk
gcp_compute_snapshot:
name: '{{snapname}}'
source_disk: '{{srcdisk.resources | first}}'
# ...
register: snapdisk
It's possible that's the issue @shamil, but the reproduction environment is no longer available to me. Do you know this works for you with the method described? It makes sense, but would be puzzling, because it actually worked sometimes for me as written, when testing repeatedly (but most of the time did not). I will test it with your suggestion at some future point if you haven't already.