-
---
-
- hosts: localhost
-
gather_facts: no
-
tasks:
-
- name: "echo pid"
-
shell: ls >/dev/null 2>&1 && echo $
-
-
register: stat_result
-
-
-
- debug: var=stat_result.stdout
-
-
-
- name: do someting else
-
-
-
action: shell ls -l
-
-
when: stat_result.stdout >1
-
register: pr
-
- debug: var=pr.stdout
Registered variables have useful attributes like :
changed – set to boolean true if something happened (useful to tell when a task has done something on a remote machine).
stderr/stdout – contains stringy output from stderr/stdout.
stdout_lines – contains a list of lines.
外加一个例子:
---
- hosts: localhost
gather_facts: no
tasks:
- shell: echo ‘first;second;third’
register: result
# result.stdout.split(';')
- debug: msg="insert into exp values ("{{result.stdout|replace(';', '","')}}");'"
这里用了split/replace。
阅读(952) | 评论(0) | 转发(0) |