Finding ansible RDS instances

随声附和 提交于 2019-12-13 01:05:07

问题


I am trying to configure with ansible my EC2 instances dynamically. I am having a problem working out how to find my RDS instances. I can set key tags but ansible ec2.py doesn't pick them up (https://github.com/ansible/ansible/issues/7564). Does any one have any suggestions?

So for instance I want an RDS instance for production, staging and for just for testing.


回答1:


If you mean the ansible ec2.py inventory script doesn't pick up RDS instances then yes I believe you're right, it will only find EC2 instances.

We have a similar setup with a seperate RDS instance for staging and production environments. The way we solved it was for any playbooks/roles that need to run against the mysql database, we run them against the magic host "localhost", and have the RDS endpoints set in variables. We use a separate variable file per environment and load them in at the beginning of the play.

e.g.

|--vars/
|    |--staging.yml
|    |--production.yml
|    
|--playbook.yml

Example "production.yml" file:

---
DB_SERVER: database-endpoint.cls4o6q35lol.eu-west-1.rds.amazonaws.com
DB_PORT: 3306
DB_USER: dbusername
DB_PASSWORD: dbpassword

Example playbook that creates a database

- name: Playbook name
  hosts: localhost
  vars_files:
    - vars/{{ env }}.yml
  tasks:

    - mysql_db: login_host={{ DB_SERVER }}
                login_user={{ DB_USER }}
                login_password={{ DB_PASSWORD }}
                login_port={{ DB_PORT }}
                collation=utf8_general_ci
                encoding=utf8
                name=databasename
                state=present

Then you can just specifiy the envionrment variable when you run the playbook.

ansible-playbook playbook.yml --extra-vars "env=production"



回答2:


The other answer is wrong now (if I'm reading the question correctly). In the same dir as your ec2.py, add a ec2.ini file, and add:

ec2.ini

[ec2]

rds = true

I had a similar issue but the docs clearly state that ec2.py can be used to find other resources.

Ansible Dynamic Inventory

There are other config options in ec2.ini, including cache control and destination variables. By default, the ec2.ini file is configured for all Amazon cloud services, but you can comment out any features that aren’t applicable. For example, if you don’t have RDS or elasticache, you can set them to False

Edit: However, I'd also like to highlight that even though it states all resources are supported by default, I didn't get RDS results until I specified I wanted them in the ec2.ini file.



来源:https://stackoverflow.com/questions/24081557/finding-ansible-rds-instances

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!