ec2_ami launch_permissions to multiple accounts

88 views
Skip to first unread message

Shmulik Alfandari

unread,
Apr 20, 2017, 4:16:05 AM4/20/17
to Ansible Project
Hi,

I am creating AMI in AWS using ec2_ami module. I need to create the AMI and to give permissions to multiple accounts,however it failed. When I am doing it with one account it's ok.
Below the code to create AMI with permission to 1 account which is working fine.

# 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: "OCCM-AUTO-AMI-4-E2E -TEST - {{ date }}"
        description: "OCCM automatically created ami for E2E"
        launch_permissions:
          user_ids: ['66602923934']
        device_mapping:
          - device_name: /dev/sda1
            size: 50
            volume_type: gp2


Could you please let me know how to pass multiple accounts to: user_ids ?

Thanks,
Shmulik.

Suporter

unread,
Apr 20, 2017, 4:29:37 AM4/20/17
to Ansible Project
You can use with_items as shown below
# 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: "OCCM-AUTO-AMI-4-E2E -TEST - {{ date }}"
        description: "OCCM automatically created ami for E2E"
        launch_permissions:
          user_ids: {{item}}
        with_items:
          - 66602923934
          - 66602923934
          - 66602923934
        device_mapping:
          - device_name: /dev/sda1
            size: 50
            volume_type: gp2


Shmulik Alfandari

unread,
Apr 20, 2017, 6:18:25 AM4/20/17
to Ansible Project
Thanks for the answer. I've done it but I got an error:

# Create AMI
    - name: Create AMI
      local_action:
        module: ec2_ami
        instance_id: i-036c3f075aebfb3ce
        #instance_id: "{{ item.id }}"
        wait: yes
        wait_timeout: 3600
        aws_access_key: "{{ AWSAccessKey }}"
        aws_secret_key: "{{ AWSSecretKey }}"
        region: "{{ region }}"
        name: "OCCM-AUTO-AMI-4-E2E -TEST - {{ date }}"
        description: "OCCM automatically created ami for E2E"
        launch_permissions:
          user_ids: "{{ item }}"
        with_items:
          - 66602923934
          - 71827345521
        device_mapping:
          - device_name: /dev/sda1
            size: 50
            volume_type: gp2

fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'item' is undefined\n\nThe error appears to have been in '/etc/ansible/playbook/E2E/create_occm_linux_ami.yml': line 96, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# Create AMI\n    - name: Create AMI\n      ^ here\n"}
        to retry, use: --limit @/etc/ansible/playbook/E2E/create_occm_linux_ami.retry


בתאריך יום חמישי, 20 באפריל 2017 בשעה 11:29:37 UTC+3, מאת Suporter:

Suporter

unread,
Apr 20, 2017, 7:01:30 AM4/20/17
to Ansible Project
userid seems to need square brackets, add them up and try

On Thursday, April 20, 2017 at 1:46:05 PM UTC+5:30, Shmulik Alfandari wrote:
Reply all
Reply to author
Forward
0 new messages