|
when: 和debug中的var 都要直接引用变量名,其他情况下都是"{{ }}"
ignore_errors: 避免一个老鼠屎坏掉一群机器
failed_when: 指鹿为马/信口雌黄
block...rescue: 应急预案
jinjia2模板中的变量值不要加双引号
- ---
- - name: Create lv
- hosts: all
- tasks:
- - name: Check vg
- shell: vgdisplay research
- register: v_result
- ignore_errors: yes
- - name: Display
- debug:
- msg: "Volumn group research does not exist"
- when: v_result.rc !=0
- failed_when: v_result.rc !=0
- - block:
- - name: Create 3G lv
- lvol:
- vg: research
- lv: data
- size: 3G
- rescue:
- - name: Msg
- debug:
- msg: "Could not create logical volume of that size"
- failed_when: true
- ignore_errors: yes
- - name: 2G
- lvol:
- vg: research
- lv: data
- size: 2G
- - name: Filesystem
- filesystem:
- fstype: vfat
- dev: /dev/research/data
- force: yes
- always:
- - name: Display
- debug:
- msg: "TEST TEST TEST"
复制代码- [student@workstation ansible]$ ansible all -m shell -a 'fsck.vfat /dev/research/data'
复制代码 serverb | CHANGED | rc=0 >>
fsck.fat 4.1 (2017-01-24)
/dev/research/data: 0 files, 1/523262 clusters
serverc | FAILED | rc=6 >>
fsck.fat 4.1 (2017-01-24)open: No such file or directorynon-zero return code
serverd | FAILED | rc=6 >>
fsck.fat 4.1 (2017-01-24)open: No such file or directorynon-zero return code
servera | CHANGED | rc=0 >>
fsck.fat 4.1 (2017-01-24)
/dev/research/data: 0 files, 1/523262 clusters
附件:
xfs: ansible all -m shell -a 'xfs_info /dev/research/data'
ext3/4: ansible all -m shell -a 'tune2fs -l /dev/research/data'
|
|