- hosts: web gather_facts: no tasks: - ping: - name: get S/N shell: show version | grep S/N | cut -f2 -d":" $2‘|sed ‘s/^[ \t]*// register: the_SN when: ("CPE") != (node.type) run_once: true - name: check S/N command: /bin/false register: result when: the_SN["stdout"] is defined and the_SN["stdout"] != (node.serialNum) ignore_errors: yes run_once: true - name: record the wrong S/N copy: content: ‘{"failed": true,"changed": false,"msg": "the sn given is not equal to system sn"}‘ dest: __result.json when: result is failed connection: local run_once: true - name: is end fail: msg=‘the sn given:{{node.serialNum}} is not equal to system sn:{{the_SN["stdout"]}}‘ when: result is failed - name: should goon debug: msg="go on..............."
[host1] 192.168.1.100 [host1:vars] ansible_ssh_user="user" ansible_ssh_port=22 ansible_ssh_pass="Password"
{"name":"xiaoming","age":18}
原文:https://www.cnblogs.com/linuxws/p/12803881.html