修改默认apache发布页面!!
vim hosts.j2
{ % for WEB in WEBS%}
{ % if WEB[ 'NAME' ] is not defined %}
< VirtualHost _default_:80 >
{ % endif%}
{ % if WEB[ 'NAME' ] is defined %}
< VirtualHost *:80 >
ServerName { { WEB[ 'NAME' ] } }
{ % endif%}
DocumentRoot { { WEB[ 'DOC' ] } }
< /VirtualHost>
{ % endfor%}
~
vim apache.yml
---
- name: install web server
hosts: all
vars:
WEBS:
- DOC: /var/www/html
INDEX: /var/www/html/index.html
INDEX_TEXT: www.westos.org
- NAME: linux.westos.org
DOC: /var/www/westos.org/linux
INDEX: /var/www/westos.org/linux/index.html
INDEX_TEXT: linux.westos.org
tasks:
- name: install apache
dnf:
name: httpd
state: present
- name: create vhost configure file
template:
src: ./hosts.j2
dest: /etc/httpd/conf.d/hosts.conf
notify: restart httpd
- name: create html dir
file:
path: "{{ item['DOC'] }}"
state: directory
loop: "{{ WEBS }}"
- name: create index.html
copy:
dest: "{{ item['INDEX']}}"
content: "{{ item['INDEX_TEXT'] }}"
loop: "{{ WEBS }}"
- name: start web server
service:
name: httpd
state: started
enabled: yes
- name: set firewalld
firewalld:
service: http
permanent: yes
state: enabled
immediate: yes
handlers:
- name: restart httpd
service:
name: httpd
state: restarted
逻辑卷创建
创建一个名为/home/student/ansible/lv.yml 的playbook,它将在所有受管节点上运行以执行下列任务
创建符合以下要求的逻辑卷:
逻辑卷创建在 research 卷组中
逻辑卷名称为 data
逻辑卷大小为 1500MiB
如果无法创建请求的逻辑卷大小,应显示错误消息
Could not create logical volume of that size,并且应改为使用大小 800MiB。
如果卷组 不存在 ,应显示错误消息
Volume group does not exist。
vim lvm.yml
---
- name: create lvm
hosts: all
tasks:
- name: check vg westos
debug:
msg: vg westos is not exist
when: ansible_facts[ 'lvm' ] [ 'vgs' ] [ 'westos' ] is not defined
- name: create 1500M exam_lvm
lvol:
vg: westos
lv: exam_lvm
size: 1500m
when: ansible_facts[ 'lvm' ] [ 'vgs' ] [ 'westos' ] is defined
ignore_errors: yes
register: LVSTATE
- name: create 800M exam_lvm
lvol:
vg: westos
lv: exam_lvm
size: 800m
when:
- ansible_facts[ 'lvm' ] [ 'vgs' ] [ 'westos' ] is defined
- LVSTATE[ 'rc' ] != 0
~
~
添加加密的用户以及组的
---
- name: create user
hosts: dev,test,prod
vars_files:
- user_list.yml
- locker.yml
tasks:
- name: create group dev
group:
name: devops
state: present
when: invertory_hostname in groups[ 'dev' ] or invertory_hostname in groups[ 'test' ]
- name: create group opsmgr
group:
name: opsmgr
state: present
when: invertory_hostname in groups[ 'prod' ]
- name: create users
user:
name: "{{ item.name }}"
groups: devops
password: "{{ pw_developer | password_hash('sha512') }}"
loop: "{{ users }}"
when:
- item.job == "developer"
- ( invertory_hostname in groups[ 'dev' ] or invertory_hostname in groups[ 'test' ] )
- name: create users for prod
user:
groups: opsmgr
name: "{{ item.name }}"
password: "{{ pw_manager|password_hash('sha512') }}"
loop: "{{ users }}"
when:
- item.job == "manager"
- invertory_hostname in groups[ 'prod' ]
- ```