首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >作为map的变量文件不考虑参数化值。

作为map的变量文件不考虑参数化值。
EN

Stack Overflow用户
提问于 2020-03-01 17:14:40
回答 1查看 130关注 0票数 0

我使用ansible来管理几个AWS资源,比如DMS。我想通过变量图来控制。将“恢复处理”或“停止”的dmsTask映射到变量,并相应地将命令传递给任务:

代码语言:javascript
复制
/vars/dms.yml

    my_dms_tasks:
      resumeProcessing:
        mainCommand: |
                    aws dms start-replication-task 
                    --replication-task-arn "{{item.RepTaskArn}}"
                    --start-replication-task-type resume-processing
        description: Resume processing
        waitCommand: aws dms wait replication-task-running --filters '[{"Name":"replication-task-arn","Values":{{replicationTaskArns}}}]'
      stopping:
        mainCommand: |
                  aws dms stop-replication-task 
                  --replication-task-arn "{{item.RepTaskArn}}"
        description: Stopping
        waitCommand: aws dms wait replication-task-stopped --filters '[{"Name":"replication-task-arn","Values":{{replicationTaskArns}}}]

这是我的根剧本:

代码语言:javascript
复制
---
- hosts: localhost
  vars:
    endpointIdentifiers: "{{endpointIdentifiers}}"
    dmsTask: "{{dmsTask}}"

  tasks:

    - name: Include vars
      include_vars: dms.yml
      register: my_dms_tasks

    - debug:
        var: dms_tasks


##### Get the relevant endpoints for identifying the corresponding dms tasks #####

##### Transform the result of 'get endpoint arn' into a Json object #####

##### Get relevant dms tasks via the aws cli #####
    - import_tasks: tasks/task_get_dms.yml

##### Transfom the result of 'get dms tasks' into a Json object #####
    - set_fact:
        replicationTaskArnsJson: "{{replicationTaskArns.results[0].stdout | from_json}}"

##### Based on the passed dmsTask act accordingly #####
    - import_tasks: tasks/task_modify_dms.yml

任务剧本如下所示:

代码语言:javascript
复制
tasks/task_modify_dms.yml
- name: Manage DMS tasks
      block:
      - name: "Resume processing DMS tasks"
        command: "{{my_dms_tasks[dmsTask].mainCommand}}"
        loop: "{{replicationTaskArnsJson.RepTasks}}"
        register: tasksResult

      - name: "Get the 'replication-task-arns' as list"
        set_fact: 
          replicationTaskArns: "{{tasksResult | json_query('results[*].item.RepTaskArn') | to_json}}"

      - name : "Show replicationTaskArns as Json"
        debug:
          var: replicationTaskArns

      # Wait for the tasks to be finished, then proceed
      - name: "Wait until DMS tasks have finished"
        command: "{{my_dms_task[dmsTask].waitCommand"
      rescue:
        - debug:
            msg: "Nothing to change"

错误是:

代码语言:javascript
复制
failed: [localhost] (item={u'Status': u'stopped', u'RepTaskIdentifier': u'guidewire-qa-pc01-gsec-ongoing', u'RepTaskArn': u'arn:aws:dms:eu-central-1:118628429710:task:MCH3GI2YVW77Y7M5N5V5KB5TSU'}) => {"ansible_loop_var": "item", "changed": true, "cmd": ["aws", "dms", "stop-replication-task", "--replication-task-arn", "{{item.RepTaskArn}}"]...

为什么“{{item.RepTaskArn}”不被解决?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-01 23:24:43

我找到了解决办法。我不得不用"import_tasks"代替"include_tasks".

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60477661

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档