【问题标题】:Create RDS database using ANSIBLE使用 ANSIBLE 创建 RDS 数据库
【发布时间】:2021-08-25 17:27:05
【问题描述】:

我想知道是否有人可以帮助我?我正在尝试使用 ansible 配置数据库 rds。 我已经创建了这个,当我尝试执行时没有任何反应:

- name: create-rds-intance
  hosts: localhost
  connection: local
  gather_facts : false

  tasks:
    - name: provision oracle rds intance
      rds:
        command: create
        region: us-west-1
        instance_name: my-db
        db_engine: oracle-se
        size: "10"
        instance_type: db.m3.xlarge
        username: root
        password: "password"
        tags:
          environment: staging

当我执行时,我什么都没有,而且我不知道如何调查正在发生的事情......

$ ansible-playbook  first-playbook-1.yml 
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [create-rds-intance] **************************************************************************************************************

TASK [provision oracle rds intance] ****************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to create instance: "}

PLAY RECAP *****************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

有没有人有一个非常简单的例子? 另外,我想知道是否可以在创建 rds 实例后立即执行 SQL 脚本?

问候,

【问题讨论】:

  • 你运行的是什么版本的ansible?
  • 您好,``` $ ansible --version ansible 2.10.3 配置文件 = 未配置模块搜索路径 = [u'/home/.../.ansible/plugins/modules', u '/usr/share/ansible/plugins/modules'] ansible python 模块位置 = /usr/lib/python2.7/site-packages/ansible 可执行位置 = /usr/bin/ansible python 版本 = 2.7.18(默认, 2020 年 8 月 27 日,21:22:52) [GCC 7.3.1 20180712 (Red Hat 7.3.1-9)] ```

标签: amazon-web-services ansible boto3 boto


【解决方案1】:

rds 模块的documentation 建议改用rds_instance

您还可能缺少一些必需的参数。我使用了rds_instance 模块来创建它,它使用以下参数:

- name: create RDS instance
  rds_instance:
    allocated_storage: 50
    availability_zone: "myaz"
    aws_access_key: "aws_access_key_id"
    aws_secret_key: "aws_secret_access_key"
    db_instance_class: "db.m5.xlarge"
    db_instance_identifier: "my-test-rds"
    db_name: "tdb"
    db_parameter_group_name: "my-oracle-param"
    db_subnet_group_name: "my-subnet"
    engine: "oracle-ee"
    engine_version: "12.1.0.2.v19"
    license_model: "bring-your-own-license"
    master_user_password: "secret"
    master_username: "dbmaster"
    max_allocated_storage: 100
    option_group_name: "my-oracle-og"
    port: "1521"
    region: "us-west-1"
    state: "present"
    storage_type: "gp2"
    vpc_security_group_ids: "sg-123456"

如果您不想将 AWS 凭证(访问密钥、秘密密钥)保留在 playbook 中,您可以从 Vault 或通过环境变量加载它们。

更新

对于第二个问题:没有直接的方法来运行 SQL 命令。在创建 RDS 后不久,我必须设置 Oracle instantclient 以使用 sqlplus 命令行进行数据库导入、架构创建之类的东西。

至少,我们需要:

  • 即时客户端基本(精简版)包
  • SQLPlus 包

【讨论】:

  • 您好,谢谢。我将使用 rds_instance 再试一次。关于我的第二个问题,您知道我是否可以在创建实例后立即执行 SQL 脚本?我的意思是在同一个ansible脚本中?
  • 您好,您能告诉我如何在同一个 ansible playbook 中引用该数据库并安装即时客户端吗?我对 ansible 很陌生,一切对我来说都是新的。
  • 模块返回endpoint。我们可以在变量中register 使用相同的变量,并将其用于进一步的连接。请参阅文档的返回代码部分。
【解决方案2】:
- name: "Load SQL script into a variable"
  set_fact:
    migration_sql: "{{ lookup('file', 'conf/migration.sql') }}"
- name: was main config file found
  debug: var=migration_sql

- name: "Execute script from variable"
  command: "psql {{ db_name }} -c {{ migration_sql }}"
  become_user: postgres
  register: sql_response_variable
- name: sql response code
  debug: var=sql_response_variable

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    相关资源
    最近更新 更多