You need to first look at the registered out snapshot_info to see what its 
dictionary looks like. After you snapshot the EC2, insert a debug: 
var=snapshot_info to see what you are being given back. With that you can to 
then construct a proper reference to the snapshot_id.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Jan 4, 2023, at 7:35 PM, SysAdmin EM <[email protected]> wrote:

I understand, I could make it work, but not by using the ec2 snapshot module.

I try to save a key as a variable but the result is empty

ok: [localhost] => {
   "ansible_facts": {
       "snap_id": ""
   },
   "changed": false
}


---
- name: "test"
 hosts: localhost
 gather_facts: no
 vars:
   aws_volume_id:
     - vol-xxxxxxxxxx
 tasks:
   - name: "create snapshot test"
     amazon.aws.ec2_snapshot:
       volume_id: "{{ item }}"
       wait_timeout: 900
       snapshot_tags:
           MarkedForDeletion: true
     register: snapshot_info
     with_items: "{{ aws_volume_id }}"


   - set_fact:
       snap_id: "{{ snapshot_info | json_query('snapshot_id')}}"


   - name: "Debug"
     debug:
       msg: "{{ snap_id }}"

This is the output

changed: [localhost] => (item=vol-xxxxxxxxxxxx) => {
   "ansible_loop_var": "item",
   "changed": true,
   "invocation": {
       "module_args": {
           "aws_access_key": null,
           "aws_ca_bundle": null,
           "aws_config": null,
           "aws_secret_key": null,
           "debug_botocore_endpoint_logs": false,
           "description": null,
           "device_name": null,
           "ec2_url": null,
           "instance_id": null,
           "last_snapshot_min_age": 0,
           "profile": null,
           "region": null,
           "security_token": null,
           "snapshot_id": null,
           "snapshot_tags": {
               "MarkedForDeletion": true
           },
           "state": "present",
           "validate_certs": true,
           "volume_id": "vol-xxxxxxxxxxx",
           "wait": true,
           "wait_timeout": 900
       }
   },
   "item": "vol-xxxxxxxxx",
   "snapshot_id": "snap-xxxxxxxxxxxx",

What am I doing wrong?

--
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
[email protected]<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAGUDtnmTWBvTZGUD2RG4kSAxv6WgDM637sFFb8kkX1Aid5t5kg%40mail.gmail.com<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2FCAGUDtnmTWBvTZGUD2RG4kSAxv6WgDM637sFFb8kkX1Aid5t5kg%2540mail.gmail.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7C6ed044846154498b9f8408daeeb4dcbd%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638084757812252284%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=rxwmJgPRLgT56C%2B2COadpg59kA1uAAPwbcplroZSooY%3D&reserved=0>.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/F8247068-62C6-4BC5-BBD6-812D7996E9DF%40nist.gov.

Reply via email to