Sounds simple, but it isn't.
I want to create a variable called "instance_role" which is set to the
aws:autoscaling:groupName
on the instance.
However, there is a formatting problem as the colons are used by Jinja and
I can't figure out how to escape them.
The role:
---
- name: Get our facts
action: ec2_facts
- name: Using the instance ID, we can get our tags
ec2_tag:
resource: "{{ ansible_ec2_instance_id }}"
state: list
region: "{{ ansible_ec2_placement_region }}"
register: instance_tags
- debug: var=instance_tags
# example output for reference
#ok: [localhost] => {
# "instance_tags": {
# "changed": false,
# "invocation": {
# "module_args": "",
# "module_name": "ec2_tag"
# },
# "tags": {
# "Name": "trainsmart-openvpnas-prod",
# "aws:autoscaling:groupName": "openvpnas",
# "environment": "access",
# "region": "eu-west-1",
# "stage": "prod"
# }
# }
#}
- name: Extract our instance role tag - ie aws:autoscaling:groupName value
set_fact:
instance_role: "{{ instance_tags.tags.aws:autoscaling:groupName }}"
- debug: var=instance_role
Outputs the following result:
root@ip-172-16-0-227:~/ansible# ansible-playbook local.yml -t get_role_tags
PLAY [Base config and return register for instance roles for final config]
****
GATHERING FACTS
***************************************************************
ok: [localhost]
TASK: [get_role_tags | Get our facts]
*****************************************
ok: [localhost]
TASK: [get_role_tags | Using the instance ID, we can get our tags]
************
ok: [localhost]
TASK: [get_role_tags | debug var=instance_tags]
*******************************
ok: [localhost] => {
"instance_tags": {
"changed": false,
"invocation": {
"module_args": "",
"module_name": "ec2_tag"
},
"tags": {
"Name": "trainsmart-openvpnas-prod",
"aws:autoscaling:groupName": "openvpnas",
"environment": "access",
"org": "trainsmart",
"region": "eu-west-1",
"stage": "prod"
}
}
}
TASK: [get_role_tags | Extract our instance role tag - ie
aws:autoscaling:groupName value] ***
fatal: [localhost] => template error while templating string: expected
token 'end of print statement', got ':'
--
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/e5b7b7f6-d239-4d01-8cdb-ba2c6953d668%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.