寻找 ansible RDS 实例 [英] Finding ansible RDS instances

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

问题描述

我正在尝试使用 ansible 动态配置我的 EC2 实例.我在确定如何找到我的 RDS 实例时遇到问题.我可以设置关键标签,但 ansible ec2.py 不会选择它们(https://github.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

然后您可以在运行剧本时指定环境变量.

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天全站免登陆