cdriehuys.rds-postgres
cdriehuys.rds-postgres
This role helps you create a PostgreSQL database using AWS' RDS service.
Requirements
This role works with AWS, so you need to have the boto
package installed, specifically version 2.26
or higher. Additionally, you need psycopg2
to connect with the database.
Role Variables
Because this role interacts with AWS, you need to provide your AWS credentials. If you don’t give them as variables, Ansible will look for them in the environment variables as explained here.
aws_access_key: your-access-key
aws_secret_key: your-secret-key
aws_region: your-aws-region
The role also uses some common AWS variables to set default names for other settings.
aws_application_name: my-application
aws_tags: {}
These parameters are used to create the database instance. You will probably want to adjust them since they are set to the smallest values by default.
db_instance_name: "{{ aws_application_name }}-db"
db_instance_size: 5
db_instance_type: db.t2.micro
db_instance_default_tags:
application: "{{ aws_application_name }}"
role: database
db_instance_tags: "{{ db_instance_default_tags | combine(aws_tags) }}"
db_instance_subnet: default
# Admin user credentials
db_admin_username: dbadmin
db_admin_password: password
By default, the RDS instance is created with a security group that allows access from anywhere while the role is running. After the role finishes, the security group will not allow any access. If you don’t know the required rules at the time of execution, we save a reference to the created security group as db_security_group
.
db_instance_sg_name: "{{ aws_application_name }}-db-sg"
db_instance_sg_description: Security group for '{{ aws_application_name }}' databases.
# Update this with your desired rules
db_instance_sg_rules: []
# Access rules during the role execution
db_instance_sg_holes:
- proto: tcp
from_port: 5432
to_port: 5432
cidr_ip: 0.0.0.0/0
Each instance can host multiple databases. You can specify databases with their names and optional parameters. Users assigned to each database will have full privileges.
db_map: {}
# Example of multiple databases with multiple users
db_map:
mydb:
users:
john: johnpassword
alice: alicepassword
otherdb:
users:
phil: philpassword
Dependencies
None
Example Playbook
Since this role uses local_action
commands, it makes sense to run it on the local machine.
- hosts: localhost
connection: local
gather_facts: no
roles:
- cdriehuys.rds-postgres
License
MIT License
Author Information
Chathan Driehuys cdriehuys@gmail.com
Role for provisioning a PostgreSQL database on RDS.
ansible-galaxy install cdriehuys.rds-postgres