On 22. mars 2017 18:44, Bhavin Parmar wrote:
*Error making code:*
   - name: "Task 3: Add string instance_id to file for each instance"
     shell: 'printf "{{ item.volume_id }}" > 
/home/ansible/playbooks/common/variables/"{{ item.item }}"'
     with_items: "{{ ec2_snap.results }}"

ec2_snap registered variable is having details of each of two snapshots in
a relevant array element. How to create loop on them?

*The extended output is as follow:*
ok: [localhost] => {
    "changed": false,
    "ec2_snap": {
        "changed": true,
        "msg": "All items completed",
        "results": [
            {
                "_ansible_item_result": true,
                "_ansible_no_log": false,
                "_ansible_parsed": true,
                "changed": true,
                "invocation": {
                    "module_args": {
                        "aws_access_key": null,
                        "aws_secret_key": null,
                        "description": "snapshot of /dev/sda1 from
i-037b5960651XXXXX taken 2017/03/22-17:19",
                        "device_name": "/dev/sda1",
                        "ec2_url": null,
                        "instance_id": "i-037b59606518XXXXX",
                        "last_snapshot_min_age": 0,
                        "profile": null,
                        "region": "us-east-1",
                        "security_token": null,
                        "snapshot_id": null,
                        "snapshot_tags": {
                            "frequency": "daily",
                            "source": "/dev/sda1"
                        },
                        "state": "present",
                        "validate_certs": true,
                        "volume_id": null,
                        "wait": true,
                        "wait_timeout": 0
                    }
                },
                "item": "i-037b59606518XXXXX",
                "snapshot_id": "snap-08d7aeda75dbXXXXX",
                "tags": {
                    "frequency": "daily",
                    "source": "/dev/sda1"
                },
                "volume_id": "vol-09aec429dfcfXXXXX",
                "volume_size": 8
            },
<snip>

I this output of ec2_snap is correct there is nothing wrong with your loop code.

Since you haven't provided any output of the error it's impossible to help.

--
Kai Stian Olstad

--
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20a73415-e201-9000-5f21-5afd8148569e%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to