ec2 ami : "msg": "AMI not updated" while retrieving new ami id

74 views
Skip to first unread message

sreenivas narayan

unread,
Apr 25, 2017, 1:27:37 AM4/25/17
to Ansible Project
Hello Guys,

I am using a playbook to create ami and trying to fetch the newely created ami id. But the debug is getting 'msg": "AMI not updated"'' Please help


-----
- name: Create ami from the instance
  local_action:
    module: ec2_ami
    aws_access_key: "{{ xxxxxxxxxxxxxx }}"
    aws_secret_key: "{{ yyyyyyyyyyyyyyyyyyyy }}"
    instance_id: "{{new_instanceid[0]}}"
    region: 'us-east-1'
    wait: yes
    wait_timeout: 1200
    name: CCCC
    tags:
      Name: newtest
      Service: TestService
  register: image

- debug: var=image

- set_fact:
    us_image_id: "{{ image.image_id }}"

- debug: var=us_image_id



-------------------------------------------------
Playbook output

  },
    "launch_permissions": {},
    "msg": "AMI not updated"


-------------------------------------------

TASK [create-ami : debug] ***********************************************************************************************************
task path: create-ami/tasks/create.yaml:16
ok: [127.0.0.1] => {
    "changed": false,
    "image": {
        "changed": false,
        "launch_permissions": {},
        "msg": "AMI not updated"
    }
}

TASK [create-ami : set_fact] ********************************************************************************************************
task path: create.yaml:18
fatal: [127.0.0.1]: FAILED! => {
    "failed": true,
    "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'dict object' has no attribute 'image_id'\n\nThe error appears to have been in 'create-ami/tasks/create.yaml': line 18, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- set_fact:\n  ^ here\n"
}




Thanks
Sreenivas


Shmulik Alfandari

unread,
Apr 25, 2017, 4:45:29 AM4/25/17
to Ansible Project

Hi,

Please do as follows:

# Create AMI
- name: Create AMI
local_action:
module: ec2_ami
instance_id: "{{ item.id }}"
wait: yes
wait_timeout: 3600
aws_access_key: "{{ AWSAccessKey }}"
aws_secret_key: "{{ AWSSecretKey }}"
region: "{{ region }}"
name: Test
description: "Test"
launch_permissions:
user_ids: ['XXXXXXXXXXXX']
device_mapping:
- device_name: /dev/sda1
size: 50
volume_type: gp2
with_items: "{{ ec2.instances }}"
register: image

- name: Print AMI ID
debug: msg="{{ image.results[0].image_id }}"

Thanks,
Shmulik.



בתאריך יום שלישי, 25 באפריל 2017 בשעה 08:27:37 UTC+3, מאת sreenivas narayan:
Reply all
Reply to author
Forward
0 new messages