ansile综合练习
原创
©著作权归作者所有:来自51CTO博客作者omaidb的原创作品,请联系作者获取转载授权,否则将追究法律责任
samba服务器搭建练习
---
- name: Install a samba server
hosts: samba_servers
user: devops
become: true
vars:
install_state: installed
random_var:
- This is colon: test
tasks:
- name: install samba
yum:
name: samba
state: "{{ install_state }}"
- name: install firewalld
yum:
name: firewalld
state: installed
- name: debug install_state variable
debug:
msg: "The state for the samba service is {{ install_state }}"
- name: start samba
service:
name: smb
state: started
enabled: yes
- name: start firewalld
service:
name: firewalld
state: started
enabled: yes
- name: configure firewall for samba
firewalld:
state: enabled
permanent: true
immediate: true
service: samba
- name: deliver samba config
template:
src: samba.conf.j2
dest: /etc/samba/smb.conf
owner: root
group: root
mode: 0644
搭建邮件服务器练习
---
# start of mailrelay playbook
- name: create mail relay servers
hosts: mailrelay
user: devops
become: true
tasks:
- name: install postfix package
yum:
name: postfix
state: installed
- name: install mail config files
template:
src: postfix-relay-main.conf.j2
dest: /etc/postfix/main.cf
owner: root
group: root
mode: 0644
notify: restart postfix
- name: check main.cf file
stat: path=/etc/postfix/main.cf
register: maincf
- name: verify main.cf file exists
debug: msg="The main.cf file exists"
when: maincf.stat.exists is defined
- name: start and enable mail services
service:
name: postfix
state: started
enabled: yes
- name: check for always_bcc
command: /usr/sbin/postconf always_bcc
register: bcc_state
ignore_errors: true
- name: email notification of always_bcc config
mail:
to: student@serverb.lab.example.com
subject: 'always_bcc setting is not empty'
body: "always_bcc is {{bcc_state.stdout}}"
when: bcc_state.stdout != 'always_bcc ='
handlers:
- name: restart postfix
service:
name: postfix
state: restarted