I had actually tried that already, and when I do I get this error: "msg": "The task includes an option with an undefined variable. The error was: 'new_ami_id' is undefined\
Which is confusing because it seems to me it clearly is being defined. On Tue, 4 Dec 2018 at 15:26, Karl Auer <[email protected]> wrote: > You need to wrap wrap the variable up in curly braces so that it is > interpreted rather than taken literally. > > I.e., where you have: > new_ami_id: ami.results[0].image_id > > you need: > new_ami_id: "{{ ami.results[0].image_id }}" > > Regards, K. > > On Wed, Dec 5, 2018 at 2:14 AM shaneoh1980 McP <[email protected]> > wrote: > >> After more searching I also tried this: >> >> --- >> - hosts: webservers >> remote_user: ubuntu >> tasks: >> - name: create an ami >> ec2_ami: >> region: eu-west-2 >> instance_id: i-0771xxxxxxxxxx >> name: "{{ inventory_hostname }}-{{ >> ansible_date_time.iso8601_basic_short }}" >> tags: >> Name: "{{ inventory_hostname }}-{{ >> ansible_date_time.iso8601_basic_short }}" >> register: ami >> >> >> - name: set ami id >> set_fact: >> new_ami_id: ami.results[0].image_id >> >> >> - pause: >> seconds: 60 >> >> >> - name: copy AMI to a different region >> ec2_ami_copy: >> source_region: eu-west-2 >> source_image_id: "{{ new_ami_id }}" >> name: "{{ new_ami_id }}" >> region: eu-west-1 >> >> But again, Ansible seems to interpret this literally: >> >> ami.results[0].image_id >> >> Rather than finding the ID of the newly created AMI. >> >> On Tuesday, 4 December 2018 12:04:52 UTC, shaneoh1980 McP wrote: >>> >>> I am trying to create a playbook which does the following: >>> >>> >>> - creates an image of an AWS instance >>> - copies the image to a different region >>> - installs updates to the instance >>> >>> >>> I can do all of this apart from getting the AMI to copy to a different >>> region. I've tried a few things but this is my current playbook (this is >>> only for the AMI creation and copying, installing updates is handled >>> separately). >>> >>> - hosts: webservers >>> remote_user: ubuntu >>> tasks: >>> - name: create an ami >>> ec2_ami: >>> region: eu-west-2 >>> instance_id: i-0771a2e4289c057e9 >>> name: "{{ inventory_hostname }}-{{ >>> ansible_date_time.iso8601_basic_short }}" >>> tags: >>> Name: "{{ inventory_hostname }}-{{ >>> ansible_date_time.iso8601_basic_short }}" >>> >>> >>> - name: set ID name >>> set_fact: >>> new_ami_name: ec2_ami.image_id >>> >>> >>> - pause: >>> seconds: 60 >>> >>> >>> - name: copy AMI to a different region >>> ec2_ami_copy: >>> source_region: eu-west-2 >>> source_image_id: "{{ new_ami_name }}" >>> name: "{{ new_ami_name }}" >>> region: eu-west-1 >>> >>> For which the creation, setting fact, and pause work, but on the last >>> part I get this error output: >>> >>> An exception occurred during task execution. To see the full traceback, >>> use -vvv. The error was: ClientError: An error occurred (InvalidAMIID. >>> Malformed) when calling the CopyImage operation: Invalid id: >>> "ec2_ami.image_id" (expecting "ami-...") >>> >>> >>> >>> >>> I've tried a few different things I'm fairly new to Ansible, but >>> basically I can't figure out how to pass the image_id of the newly created >>> AMI to the next play so that it can use this as the basis of the copying. >>> >>> I can see clearly that it's not registering the image_id as it's saying >>> it's not in the expected "ami-" format, but I'm stuck from there. >>> >>> >> -- >> 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/8995dac7-5f1b-470f-b1e6-11ce3b1a4074%40googlegroups.com >> <https://groups.google.com/d/msgid/ansible-project/8995dac7-5f1b-470f-b1e6-11ce3b1a4074%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > Karl Auer > > Email : [email protected] > Website: http://2pisoftware.com > > GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816 > Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Ansible Project" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/ansible-project/ouLsLPAFuec/unsubscribe. > To unsubscribe from this group and all its topics, 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/CA%2B%2BT08SN%3DZL1hX%3DBEBCB%3DYKi40rhd6Y%2BHeCTkopjOKRFgS6zEQ%40mail.gmail.com > <https://groups.google.com/d/msgid/ansible-project/CA%2B%2BT08SN%3DZL1hX%3DBEBCB%3DYKi40rhd6Y%2BHeCTkopjOKRFgS6zEQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAEu1aFzMhVJ-ZGiE0tG48vvRw42Z3tR5qFmGTKxOD33kWvygeQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
