On 23.03.2017 03:55, Bhavin Parmar wrote:
*When trying to access with_items, with following code:*

   - name: "Task 3: Add string instance_id to file for each instance"
     shell: 'printf "{{ item.volume_id }}"'
     #shell: 'printf "{{ item.volume_id }}" >
/home/ansible/playbooks/common/variables/"{{ item.item }}"'
     with_items:
       - "{{ ec2_snap.results }}"

*Rather than giving proper output, as appeared in above manual access, it
gives garbrage as follow:*

This is not garbage, its a verbose output of what Ansible is doing.
I have commented the interesting part below.


changed: [localhost] => (item={'_ansible_parsed': True, u'changed': True,
'_ansible_no_log': False, 'item': u'i-04452f010e4cXXXXX',
'_ansible_item_result': True, u'volume_size': 15, u'snapshot_id':
u'snap-0fa1ec99d379XXXXX', u'volume_id': u'vol-0e0516ea9623XXXXX',
u'invocation': {u'module_args': {u'aws_secret_key': None, u'profile': None,
u'aws_access_key': None, u'description': u'snapshot of /dev/sda1 from
i-04452f010e4cXXXXX taken 2017/03/22-19:58', u'security_token': None,
u'snapshot_tags': {u'source': u'/dev/sda1', u'frequency': u'daily'},
u'region': u'us-east-1', u'snapshot_id': None, u'device_name':
u'/dev/sda1', u'instance_id': u'i-04452f010e4cXXXXX', u'state': u'present',
u'wait_timeout': 0, u'ec2_url': None, u'last_snapshot_min_age': 0,
u'validate_certs': True, u'volume_id': None, u'wait': True}}, u'tags':
{u'source': u'/dev/sda1', u'frequency': u'daily'}}) => {
    "changed": true,
    "cmd": "printf \"vol-0e0516ea9623XXXXX\"",

Here you see that ansible is running
printf "vol-0e0516ea9623XXXXX"
as you wanted with you loop.


    "delta": "0:00:00.002131",
    "end": "2017-03-22 19:58:13.225366",
    "invocation": {
        "module_args": {
            "_raw_params": "printf \"vol-0e0516ea962XXXXX\"",
            "_uses_shell": true,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "warn": true
        }
    },
    "item": {
        "changed": true,
        "invocation": {
            "module_args": {
                "aws_access_key": null,
                "aws_secret_key": null,
                "description": "snapshot of /dev/sda1 from
i-04452f010e4cacb0b taken 2017/03/22-19:58",
                "device_name": "/dev/sda1",
                "ec2_url": null,
                "instance_id": "i-04452f010e4cXXXXX",
                "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-04452f010e4XXXXX",
        "snapshot_id": "snap-0fa1ec99d379XXXXX",
        "tags": {
            "frequency": "daily",
            "source": "/dev/sda1"
        },
        "volume_id": "vol-0e0516ea9623XXXXX",
        "volume_size": 15
    },
    "rc": 0,
    "start": "2017-03-22 19:58:13.223235",
    "stderr": "",
    "stderr_lines": [],
    "stdout": "vol-0e0516ea962XXXXX",
    "stdout_lines": [
        "vol-0e0516ea9623XXXXX"

The output of the command above is in stdout and stdout_lines.
vol-0e0516ea962XXXXX is the output of the printf command.

This is working as it should, what were you expecting?

--
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/c1bd57d9774bc1710e83d07a27811f67%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to