Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1068745
  • 博文数量: 186
  • 博客积分: 4939
  • 博客等级: 上校
  • 技术积分: 2075
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-08 17:15
文章分类

全部博文(186)

文章存档

2018年(1)

2017年(3)

2016年(11)

2015年(42)

2014年(21)

2013年(9)

2012年(18)

2011年(46)

2010年(35)

分类: 系统运维

2015-07-17 15:27:01


  1. ---
  2. - hosts: localhost
  3. gather_facts: no
  4. tasks:
  5. - name: "echo pid"
  6. shell: ls >/dev/null 2>&1 && echo $
  7. register: stat_result
  8. - debug: var=stat_result.stdout
  9. - name: do someting else
  10. action: shell ls -l
  11. when: stat_result.stdout >1
  12. register: pr
  13. - 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。



阅读(870) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~