RHCE考前辅导讲解《二》
课程第13,14天均为RHCE考试内容,学习总结为结合课本第16章及考试内容。
- 创建和使用逻辑卷
# vim lv.yml
---
- name: 创建和使用逻辑卷
hosts: all
tasks:
- block:
- name: one
lvg:
vg: research
pvs: /dev/sdb
pesize: 150M
- name: two
lvol:
vg: research
lv: data
size: 150M
- name: three
filesystem:
fstype: ext4
dev: /dev/research/data
rescue:
- debug:
msg: "Could not create logical volume of that size"
- 判断主机组名
# vim issue.yml
---
- name: 修改文件内容
hosts: all
tasks:
- name: one
copy:
content: 'Development'
dest: /etc/issue
when: "inventory_hostname in groups.dev"
- name: two
copy:
content: 'Test'
dest: /etc/issue
when: "inventory_hostname in groups.test"
- name: three
copy:
content: 'Production'
dest: /etc/issue
when: "inventory_hostname in groups.prod"
- 管理文件属性
# vim chmod.yml
---
- name: 管理文件属性
hosts: dev
tasks:
- name: one
file:
path: /linuxprobe
state: directory
owner: root
group: root
mode: '2775'
- name: two
file:
src: /linuxprobe
dest: /linuxcool
state: link
- 管理密码库文件
ansible-vault 命令
create 新建
encrypt 加密
decrypt 解密
rekey 修改口令
view 查看
第一步:编写剧本,保存两个变量名
# vim locker.yml
---
pw_developer: Imadev
pw_manager: Imamgr
第二步:编写密码并赋权,修改配置文件,密码保存路径
# vim /root/secret.txt
whenyouwishuponastar
# chmod 600 /root/secret.txt
#vim ansible.cfg //修改配置文件
140 vault_password_file= /home/greg/ansible/secret.txt
第三步:加密
ansible-vault encrypt locker.yml
修改密码
ansible-vault rekey --ask-vault-pass locker.yml
第四步:查看和修改加密后的文件内容
ansible-vault edit locker.yml //修改
ansible-vault view locker.yml //查看