ansible优秀案例
# 优化的取消交换分区
- name: Remove swapfile from /etc/fstab
mount:
name: "{{ item }"
fstype: swap
state: absent
with_items:
- swap
- none
- name: check swap
command: /sbin/swapon -s
register: swapon
changed_when: no
- name: Disable swap
command: /sbin/swapoff -a
when:
- swapon.stdout
ignore_errors: yes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- name: shutdown get the status of swap
shell: grep swap /etc/fstab l grep -c "#
register: swap
ignore errors: yes
tags: swap
- name: shutdown swapoff -a
shell: swapoff -a
when: swap.stdout == "0"
ignore errors: yes
tags: swap
- name: shutdown | 注释/etc/fstab/swap 那一行
replace: dest=/etc/fstab regexp='(.*) swap(\s+) swap' replace='f swap\2swap'
when: swap.stdout == "0"
ignore errors: yes
tags: swap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
上次更新: 2023/01/31, 21:32:57