查找Ansible RDS实例 [英] Finding ansible RDS instances

查看:96
本文介绍了查找Ansible RDS实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ansible动态配置EC2实例.我在解决如何找到我的RDS实例时遇到问题.我可以设置密钥标签,但是ansible ec2.py不会将其选中( https://github.com. com/ansible/ansible/issues/7564 ).有人有建议吗?

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?

例如,我想要一个RDS实例用于生产,暂存和仅用于测试.

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

推荐答案

如果您的意思是ansible ec2.py清单脚本没有获取RDS实例,那么我相信您是对的,它只会找到EC2实例.

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.

我们有一个类似的设置,带有用于暂存和生产环境的单独的RDS实例.解决问题的方法是针对需要针对mysql数据库运行的任何剧本/角色,针对不可思议的主机"localhost"运行它们,并在变量中设置RDS端点.我们在每个环境中使用单独的变量文件,并在播放开始时将其加载.

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.

例如

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

"production.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

创建数据库的示例剧本

- 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

然后,您只需在运行剧本时指定envionrment变量即可.

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

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

这篇关于查找Ansible RDS实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆