Ansible fetching Stdout key value

问题描述 投票:0回答:1

我需要一些有关如何使用Ansible获取特定值的帮助

我的任务:

- name: 'check Describe Information'
  debug: 
  var: describeresult.stdout

我需要从stdout下面获取IP地址值,应该在debug var中放入什么以获取IP地址

TASK [check Describe Information] **********************************************
task path: /home/tom/Getipaddress.yml:28
ok: [127.0.0.1] => {
    "describeresult.stdout": {
        "failures": [], 
        "tasks": [
            {
                "attachments": [
                    {
                        "details": [
                            {
                                "name": "subnetId", 
                                "value": "subnet-xxxxxxxxxxxxxx"
                            }, 
                            {
                                "name": "networkInterfaceId", 
                                "value": "eni-xxxxxxxxxxxxxxxx"
                            }, 
                            {
                                "name": "macAddress", 
                                "value": "xxxxxxxxxxxxxxxxxx"
                            }, 
                            {
                                "name": "privateIPv4Address", 
                                "value": "xxxxxxxxxxxxxxxxxx"
                            }

此外,我正在使用AWS ECS命令以--output作为JSON生成上述输出,不确定如何使用--query仅过滤或获取以上IP地址

json amazon-web-services dictionary ansible amazon-ecs
1个回答
0
投票
使用json_query。例如

- set_fact: my_privateIPv4Address: "{{ describeresult.stdout.tasks| json_query(query) }}" vars: query: "[].attachments[].details[?name=='privateIPv4Address'].value"

[json_query默认返回列表。
© www.soinside.com 2019 - 2024. All rights reserved.