使用Ansible制成列表的脚本输出

时间:2018-09-13 09:15:13

标签: ansible

通过使用Ansible执行shell管理脚本,我得到了在Kafka集群上配置的主题列表。

- name: List Topics
  command: "{{ kafka_bin_dir }}/{{ kafka_topic_script }}
            --zookeeper {{ prefix }}-kafka-{{ Kafka_node }}.{{ DNSDomain}}:{{ zookeeper_port }} --list"
  register: topicList

- name: Display Topic List
  debug: var=topicList.stdout_lines

- name: Describe Topics
  command: "{{ kafka_bin_dir }}/{{ kafka_topic_script }}
            --zookeeper {{ prefix }}-kafka-{{ Kafka_node }}.{{ DNSDomain}}:{{ zookeeper_port }} --describe  --topic {{ item }}"
  with_items: "{{ topicList.stdout_lines }}"
  register: topicDescription

- name: Display Description
  debug: var=topicDescription.results
  register: describeOutput

我使用列表来--describe的每个主题。结果,我得到了复杂的输出。

"topicDescription.results": [
    {
        "_ansible_ignore_errors": null,
        "_ansible_item_label": "ADMIN.TOPIC",
        ...
        "cmd": [
            "/data01/app/kafka/current/dist/kafka/bin/kafka-topics.sh",
            "--zookeeper",
            ...
        ],
        "delta": "0:00:01.758765",
        "end": "2018-09-13 18:08:57.838810",
        "failed": false,
        "invocation": {
            "module_args": {
                "_raw_params": "/data01/app/kafka/current/dist/kafka/bin/kafka-topics.sh --zookeeper dev6-kafka-node1.efx.extnp.national.com.au:2181 --describe --topic ADMIN.TOPIC",
            ...
            }
        },
        "item": "ADMIN.TOPIC",
        "rc": 0,
        "start": "2018-09-13 18:08:56.080045",
        "stderr": "",
        "stderr_lines": [],
        "stdout": 

"Topic:ADMIN.TOPIC\tPartitionCount:6\tReplicationFactor:2\tConfigs:file.delete.delay.ms=60000,segment.ms=60000,min.compaction.lag.ms=0,retention.bytes=-1,segment.index.bytes=10485760,cleanup.policy=delete,message.timestamp.diffe...: 1\tLeader: 
...,
            "stdout_lines": [
                "Topic:ADMIN.TOPIC\tPartitionCount:6\tReplicationFactor:2\tConfigs:file.delete.delay.ms=60000,segment.ms=60000,min.compaction.lag.ms=0,retention.bytes=-1,segment.index.byt...5",
                "\tTopic: ADMIN.TOPIC\tPartition: 0\tLeader: 1\tReplicas: 1,0\tIsr: 1,0",
                ...
        ]
    },
    {
        "_ansible_ignore_errors": null,
        "_ansible_item_label": "ADMIN.TOPIC2",
        ....
        "changed": true,
        "cmd": [
            "/data01/app/kafka/current/dist/kafka/bin/kafka-topics.sh",
            "--zookeeper",
            ...
        ],
        "delta": "0:00:01.744354",
        "end": "2018-09-13 18:08:59.897350",
        "failed": false,
        "invocation": {
            "module_args": {
            ...
            }
        },
        "item": "ADMIN.TOPIC2",
        "rc": 0,
        "start": "2018-09-13 18:08:58.152996",
        "stderr": "",
        "stderr_lines": [],
        "stdout": 

"Topic:ADMIN.TOPIC2\tPartitionCount:6\tReplicationFactor:2\tConfigs:file.delete.delay.ms=60000,segment.ms=43200000,min.compaction.lag.ms=0,retention.bytes=-1,segment.index.bytes=10485760,cleanup.policy=compact,message.timestamp.difference.max.ms=9223372036854775807,segment.jitter.ms=0,message.timestamp.type=CreateTime,message.format.version...: 1\tLeader: 
...,
            "stdout_lines": [
                "Topic:ADMIN.TOPIC2\tPartitionCount:6\tReplicationFactor:2\tConfigs:file.delete.delay.ms=60000,segment.ms=43200000,min.compaction.lag.ms=0,retention.bytes=-1,segment.index...1",
                "\tTopic: ADMIN.TOPIC2\tPartition: 0\tLeader: 2\tReplicas: 2,1\tIsr: 2,1",
                ...
            ]
        },
        {
            "_ansible_ignore_errors": null,
            "_ansible_item_label": "FX.REF_DATA.PRODUCT",
            "_ansible_item_result": true,
            "_ansible_no_log": false,
            ...
        }
    ]
}

如何优化输出以获取上面复杂输出中每个条目的stdoutstdout_lines

0 个答案:

没有答案