Last active
October 1, 2018 04:31
-
-
Save tomwwright/58443c76f6d4bfee7f8c8bce6bbebc93 to your computer and use it in GitHub Desktop.
Medium : Ansible and AWS CLI : idempotent Aurora clusters example https://medium.com/@tomwwright/ansible-and-the-aws-cli-no-module-no-problem-27580d36ef2d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: localhost | |
vars: | |
aurora_cluster_name: mycoolauroracluster | |
aurora_cluster_engine: aurora-mysql | |
aurora_cluster_version: 5.7.12 | |
aws_region: ap-southeast-2 | |
tasks: | |
- name: look for an existing Aurora cluster using the AWS CLI | |
command: > | |
aws rds describe-db-clusters | |
--filters Name=db-cluster-id,Values={{ aurora_cluster_name }} | |
--region {{ aws_region }} | |
changed_when: false | |
register: aurora_cluster_query | |
- name: parse the response and check if our Aurora cluster is there | |
set_fact: | |
aurora_cluster: "{{ aurora_cluster_query.stdout | from_json | json_query('DBClusters[0]')}}" | |
- name: create Aurora Cluster with the AWS CLI if it doesn't exist | |
command: > | |
aws rds create-db-cluster | |
--region {{ aws_region }} | |
--cli-input-json '{{ lookup('template', 'create-db-cluster.json.j2') | to_json }}' | |
when: aurora_cluster == '' # json_query returns an empty string if it doesn't resolve right, nice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"DBClusterIdentifier": "{{ aurora_cluster_name }}", | |
"Engine": "{{ aurora_cluster_engine }}", | |
"EngineVersion": "{{ aurora_cluster_version }}", | |
"MasterUsername": "ansible", | |
"MasterUserPassword": "supersecure" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment