- hosts: all gather_facts: no become: yes tasks: - name: Install traceroute package: name: "{{item}}" state: present with_items: - traceroute - name: check ip shell: "{{item}}" register: check_ip_list with_items: - traceroute -T -p 22 10.252.19.36 |tail -n 1 - name: delete check delegate_to: localhost run_once: true file: state: absent path: ./check_ip.log ignore_errors: yes - name: check delegate_to: localhost blockinfile: path: ./check_ip.log owner: tiantao01 group: tiantao01 create: yes marker: "" block: | {{inventory_hostname}} {{item.cmd.strip()}} {{item.stdout.strip().split('\n')[-1]}} when: - not (item.cmd.split(' ')[-4].strip()) in (item.stdout.strip().split('\n')[-1]) loop: "{{check_ip_list.results}}"
标签:脚本,name,ip,item,ansible,strip,yes,check From: https://www.cnblogs.com/tiantao36/p/18102515