20201031,RHCE考前辅导二
(8)创建逻辑卷
-
name: 创建和使用逻辑卷
host: all
tasks:
-block:
-name: one
lvol:
vg:research
lv: data
size: 1500-name: two filesystem: fstype: ext4 dev: /dev/research/date
recue:
-debug:
msg: could not created xxx
-name: three
lvol:
vg:research
lv: data
size: 800
when: ansible_lvm.vgs.research is defined
-debug:
msg: Volume group done not exist
when: ansible_lvm.vgs.research is undefined
(9)生成主机文件
wget http://materials/hosts.j2 /home/greg/ansible/
vim host.yml
- name: 生成主机文件
hosts: dev
tasks:- name: one
template:
src: /home/greg/ansible/hosts.j2
dst: /etc/myhosts
- name: one
host.j2
{% for host in groups[ ‘all’ ] %}
{{ hostvars[host][ ‘ansible_facts’ ][ ‘default_ipv4’ ][ ‘address’ ] }}
{{ hostvars[host][ ‘ansible_facts’ ][ ‘fqdn’ ] }}
{{ hostvars[host][ ‘ansible_facts’ ][ ‘hostname’ ] }}
{% endfor %}
(10)修改文件内容
vim /home/grep/ansible/issue.yml
- name: 修改文件内容
hosts: all
task:- name: one
shell: “xxxx”
copy:
content: ‘Development’
dest: /etc/issue
when: “inventory_hostname in groups.dev” - name: two
shell: “xxxx”
copy:
content: ‘Test’
dest: /etc/issue
when: “inventory_hostname in groups.test” - name: three
shell: “xxxx”
copy:
content: ‘Production’
dest: /etc/issue
when: “inventory_hostname in groups.prod”
- name: one
(11)创建web内容目录
vim /home/greg/ansible/webcontent.yml
- name: 创建web内容目录
host: all
task:- name: one
file:
path: /webdev
state: directory
group: webdev
mode: ‘2775’ 02:14:42疑问为什么是2775 - name: two
file:
src: /webdev
dst: /var/www/html/webdev
state: link - name: three
file:
copy:
content: “Devlepmet”
dest: /dev
- name: one