首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可行的寄存器访问invocation_module?

可行的寄存器访问invocation_module?
EN

Stack Overflow用户
提问于 2020-05-21 12:36:06
回答 1查看 257关注 0票数 0

我有一个从S3下载文件列表的攻略,这个列表可以通过使用with_items和|default([])动态设置。

拉出此命令后,我需要获取存储文件的目的地列表,并执行其他操作。我注册了var output,并看到调用module_args具有值"Dest“,这就是我想要访问的内容。

我试过这样的东西:

代码语言:javascript
复制
debug: msg="{{ item }}"
with_items: "{{ output.results }}

或者甚至访问output.invocation但得到未定义的变量

任务:

代码语言:javascript
复制
  - name: "Download Apps from S3"
    aws_s3:
      bucket: "{{ resource_bucket_name }}"
      object: "{{ s3_apps[item].src }}"
      dest: "{{ s3_apps[item].dest }}"
      mode: get
    with_items: "{{ s3_apps_decl |default([]) }}"
    register: output

我的带debug的输出变量:

代码语言:javascript
复制
    "msg": [
        {
            "ansible_loop_var": "item",
            "changed": true,
            "failed": false,
            "invocation": {
                "module_args": {
                    "aws_access_key": null,
                    "aws_secret_key": null,
                    "bucket": "bucket-resources",
                    "debug_botocore_endpoint_logs": false,
                    "dest": "/tmp/test_app.tgz",
                    "dualstack": false,
                    "ec2_url": null,
                    "encrypt": true,
                    "encryption_kms_key_id": null,
                    "encryption_mode": "AES256",
                    "expiry": 600,
                    "headers": null,
                    "ignore_nonexistent_bucket": false,
                    "marker": "",
                    "max_keys": 1000,
                    "metadata": null,
                    "mode": "get",
                    "object": "test_app.tgz",
                    "overwrite": "always",
                    "permission": [
                        "private"
                    ],
                    "prefix": "",
                    "profile": null,
                    "region": null,
                    "retries": 0,
                    "rgw": false,
                    "s3_url": null,
                    "security_token": null,
                    "src": null,
                    "validate_certs": true,
                    "version": null
                }
            },
            "item": "test_app",
            "msg": "GET operation complete"
        },
        {
            "ansible_loop_var": "item",
            "changed": true,
            "failed": false,
            "invocation": {
                "module_args": {
                    "aws_access_key": null,
                    "aws_secret_key": null,
                    "bucket": "bucket-resources",
                    "debug_botocore_endpoint_logs": false,
                    "dest": "/tmp/testanotherapp.spl",
                    "dualstack": false,
                    "ec2_url": null,
                    "encrypt": true,
                    "encryption_kms_key_id": null,
                    "encryption_mode": "AES256",
                    "expiry": 600,
                    "headers": null,
                    "ignore_nonexistent_bucket": false,
                    "marker": "",
                    "max_keys": 1000,
                    "metadata": null,
                    "mode": "get",
                    "object": "testanotherapp.spl",
                    "overwrite": "always",
                    "permission": [
                        "private"
                    ],
                    "prefix": "",
                    "profile": null,
                    "region": null,
                    "retries": 0,
                    "rgw": false,
                    "s3_url": null,
                    "security_token": null,
                    "src": null,
                    "validate_certs": true,
                    "version": null
                }
            },
            "item": "testanotherapp",
            "msg": "GET operation complete"
        }
    ]
}

我期望的输出是定义一个变量,该变量输出:['/tmp/testanotherapp.spl'.'/tmp/test_app.tgz']

我已经用与上面任务类似的语法尝试了set_fact,但是它只保存最后一个值...

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-21 16:20:37

你在output中所期望的就是你所得到的,因为你正在接收你是registering in a loopreturn values from an aws_s3 module call

现在,如果您只想获取已保存在目标主机上的所有dest的路径列表,则必须从数据结构中执行extract the corresponding attribute

代码语言:javascript
复制
- name: Show a list of dest paths from previous run
  debug:
    msg: "{{ output.results | map(attribute='invocation.module_args.dest') | list }}"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61927366

复制
相关文章

相似问题

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