字符串列表的整数列表ANSIBLE

时间:2018-04-12 03:24:04

标签: amazon-web-services ansible yaml

我正在创建一个运行AWS命令的任务,如下所示:

- name: Disassociates all current members
  command: sh -c 'aws guardduty disassociate-members --account-ids "{{ member_ids }}" --detector-id "{{ detector_id }}" --region "{{ TARGET_AWS_REGION }}"'
  environment:
    AWS_ACCESS_KEY_ID: "{{ assumed_role.sts_creds.access_key }}"
    AWS_SECRET_ACCESS_KEY: "{{ assumed_role.sts_creds.secret_key }}"
    AWS_SESSION_TOKEN: "{{ assumed_role.sts_creds.session_token }}"
  register: response

其中 member_ids 是来自另一个命令的列表:

set_fact: 
    member_ids: "{{ (response.stdout | from_json).Members | map(attribute='AccountId') | list | to_json }}"

member_ids

ok: [localhost] => {
"member_ids": [
    "123456789123", 
    "456654879899", 
    "654897987955"
]

}

但后来我发现了一个错误:

"Invalid type for parameter AccountIds[0], value: 123456789123, type: <type 'int'>, valid types: <type 'basestring'>",
"Invalid type for parameter AccountIds[1], value: 456654879899, type: <type 'int'>, valid types: <type 'basestring'>",
"Invalid type for parameter AccountIds[2], value: 654897987955, type: <type 'int'>, valid types: <type 'basestring'>",

这意味着AWS命令需要一个字符串列表。那么如何将 member_ids 列表中的所有值从int值转换为字符串值?

任何指针都将受到赞赏。

0 个答案:

没有答案