【问题标题】:Creating RDS in ansible在ansible中创建RDS
【发布时间】:2016-10-25 01:51:13
【问题描述】:

我正在努力为工作学习 ansible。我需要创建 RDS 实例,然后是数据库并获取环境变量。

我总是出错

致命:[本地主机]:失败! => {"changed": false, "failed": true, "msg": "unsupported parameter for module: register"}

这是我的代码

- name: Configure RDS
  hosts: localhost
  connection: local
  gather_facts: false

  tasks:
    - name: Provision RDS
      rds:
        command: create
        instance_name: ANSIBLEDataloading
        db_engine: Postgresql
        size: 10
        instance_type: sb.m1.small
        username: xxxxx
        password: xxxxx
        tags:
          Environment: Dataloading
          Application: sims
        command: facts
        instance_name: ANSIBLEDataloading
        register: ANSIBLEDataloading
    - name: Add new instance to host group
      add_host: hostname={{ item.endpoint }} groupname=launched_db
      with_items: '{{ANSIBLEDataloading.instance}}'

我正在努力学习,对 ansible 非常陌生。

新代码

- name: Configure RDS
  hosts: localhost
  connection: local
  gather_facts: false

  tasks:
    - name: Provision RDS
      rds:
        command: create
        instance_name: ANSIBLEDataloading
        db_engine: postgres
        region: 'us-east-1'
        size: 10
        instance_type: db.m3.xlarge
        username: xxxxx
        password: xxxx
        tags:
          Environment: Dataloading
          Application: sims
      register: ANSIBLEDataloading
    - name: Add new instance to host group
      add_host: hostname={{ item.endpoint }} groupname=launched_db
      with_items: '{{ANSIBLEDataloading.instance}}'

新错误

fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'unicode object' has no attribute 'endpoint'\n\nThe error appears to have been in '/Users/suyesh/Desktop/ansible_conversion/conversion.yml': line 48, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n      register: ANSIBLEDataloading\n    - name: Add new instance to host group\n      ^ here\n"}

【问题讨论】:

    标签: ansible ansible-playbook amazon-rds


    【解决方案1】:

    您遇到的错误只是格式错误。寄存器应该和任务在同一个缩进。

      tasks:
        - name: Provision RDS
          rds:
            command: create
            instance_name: ANSIBLEDataloading
            db_engine: Postgresql
            size: 10
            instance_type: sb.m1.small
            username: xxxxx
            password: xxxxx
            tags:
              Environment: Dataloading
              Application: sims
            command: facts
            instance_name: ANSIBLEDataloading
          register: ANSIBLEDataloading
    

    【讨论】:

    • 我现在收到这个错误,我会在上面更新。致命的:[本地主机]:失败! => {"failed": true, "msg": "字段 'args' 的值无效,似乎包含一个未定义的变量。错误是:'unicode object' has no attribute 'endpoint'\n \n错误似乎出现在“/Users/suyesh/Desktop/ansible_conversion/conversion.yml”中:第 48 行,第 7 列,但可能\n在文件中的其他位置,具体取决于确切的语法问题。\n\n有问题的行似乎是:\n\n 注册:ANSIBLEDataloading\n - 名称:将新实例添加到主机组\n ^ 此处\n"}
    • 你在哪里定义变量“端点”?您是否提供了整个剧本文件?错误消息表明您尚未将“端点”定义为变量,并且在您提供的代码中我看不到您有/没有的地方。
    • 这就是我的全部剧本。
    • 我想创建 rds,然后在其中创建一个数据库并获取它的凭据
    • 那你现在的问题是你调用了一个你没有定义的变量(端点)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    • 2017-10-01
    • 1970-01-01
    相关资源
    最近更新 更多