So far I came up with the following, but it does feel a bit kludgy:
- name: check if running inside AWS
uri:
url: http://169.254.169.254/latest/meta-data
timeout: 2
register: aws_uri_check
failed_when: False
- name: store result
set_fact:
inside_aws: "{{ aws_uri_check.status == 200 }}"
- name: install aws cli
command: pip install awscli
when: inside_aws
- name: get the list of tags
shell: REGION=$(curl -q
http://169.254.169.254/latest/meta-data/placement/availability-zone)
INSTANCE=$(curl -q http://169.254.169.254/latest/meta-data/instance-id);
aws ec2 describe-tags --region ${REGION%?} --filters
"Name=resource-id,Values=$INSTANCE"
register: tag_list
when: inside_aws
- name: create facts out of the tags
set_fact:
"{{'ec2_tag_' + tag.Key.replace(':','_').replace('-','_') }}": "{{
tag.Value }}"
with_items: "{{ (tag_list.stdout | from_json)['Tags'] }}"
when: inside_aws
loop_control:
loop_var: tag
label: "{{ tag.Key }}"
- name: remove awscli tools
command: pip uninstall -y awscli
when: inside_aws
kind regards
Pshem
--
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/a0ad9cbb-208a-4491-bed2-37b472920acc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.