Я использую ansible для управления несколькими AWS ресурсами, такими как DMS. Я хочу контролировать через карту переменных. Задача dmsTask, которая является «обработкой возобновления» или «остановкой», сопоставляется с переменной, и команды передаются задаче соответственно:
/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}}}]
Это моя root книга воспроизведения:
---
- 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
Сборник задач выглядит следующим образом:
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"
Ошибка:
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}}» не разрешается?