Hi I am able to get the desired output in my playbook below where I am using 2 tasks as follows aws-create-rds
and aws-create-route53-record
---
# Playbook for creating aws rds instance and then creating route53 dns record.
- name: setup aws-rds-instances
hosts: localhost
roles:
- aws-create-rds
task definition for the aws-create-rds
is as below.
---
- name: create an rds instance
rds:
command: create
aws_access_key: "{{ aws_create_rds.access_key }}"
aws_secret_key: "{{ aws_create_rds.secret_key }}"
db_name: "{{ aws_create_rds.db_name }}"
instance_name: "{{ aws_create_rds.name }}"
db_engine: "{{ aws_create_rds.db_engine }}"
size: "{{ aws_create_rds.db_size }}"
instance_type: "{{ aws_create_rds.instance_type }}"
username: "{{ aws_create_rds.username }}"
password: "{{ aws_create_rds.password }}"
subnet: "{{ aws_create_rds.subnet }}"
region: "{{ aws_create_rds.region }}"
zone: "{{ aws_create_rds.zone }}"
publicly_accessible: "{{ aws_create_rds.access }}"
backup_retention: "{{ aws_create_rds.retention }}"
vpc_security_groups: "{{ aws_create_rds.aws_sg_name }}"
port: "{{ aws_create_rds.port }}"
wait: yes
wait_timeout: 900
tags:
created_by: ansible
register: rds
- name: Create a route53 record for RDS instance.
route53:
state: present
aws_access_key: "{{ aws_create_route53_record.access_key }}"
aws_secret_key: "{{ aws_create_route53_record.secret_key }}"
zone: "{{ aws_create_route53_record.zone }}"
hosted_zone_id: "{{ aws_create_route53_record.id }}"
type: "{{ aws_create_route53_record.type }}"
value: "{{ rds.instance.endpoint }}"
record: "{{ aws_create_route53_record.record }}"
private_zone: "{{ aws_create_route53_record.private_zone }}"
ttl: 30
Now since the there are 2 task in this task I want them to split into 2 different roles. 1st as aws-create-rds
and 2nd as aws-create-route53-record
I would want to use them as independent roles in ansible in future however I am not sure how I can pass endpoint
value coming from aws-create-rds
task and pass it to aws-create-route53-record
and use it as value
in route53
dns record. I've checked rds module documentation and there is no return value for endpoint in it. Also there are 2 use cases for this given as below.
1. route53 record value can be passed through group_vars OR
2. route53 record value can be passed from any previous ansible task executed.
I want to handle both the condition in aws-create-route53-record
task. Any clue how this can be achieved. Environment variable or anything. Thanks in advance.
In order to achieve this I wrote 2 different roles/tasks and calling them in a playbook. Below are the tasks. First is called aws-create-rds
And second task is aws-create-route53-record.