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/daterecue:
-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
这篇博客介绍了如何使用Ansible进行自动化运维,包括创建和使用逻辑卷、生成主机文件以及修改文件内容。在创建逻辑卷任务中,涉及到了VG(volume group)和LV(logical volume)的配置,并根据条件执行不同操作。生成主机文件的任务通过模板渲染实现了动态生成。最后,根据主机分组修改不同环境的文件内容,分别写入'Development','Test'和'Production'。

983

被折叠的 条评论
为什么被折叠?



