Ansible命令模塊(mount模塊 selinux模塊 firewalld模塊 )


 

1.磁盤掛載mount模塊

1)幫助語法

EXAMPLES: # Before 2.3, option 'name' was used instead of 'path'
- name: Mount DVD read-only mount: path: /mnt/dvd #掛載的目錄(nfs客戶端) src: /dev/sr0 #遠端被掛載的目錄 (nfs服務端) fstype: nfs #掛在類型 opts: ro,noauto #自動掛載的參數 state: present #寫入自動掛載,但實際沒有掛咋,需要重啟服務器 unmounted #取消臨時掛載,但是沒有清理自動掛載 mounted #寫入自動掛載,並且直接掛載了(常用) absent #取消臨時掛載,並且清理自動掛載(常用)

 

2)准備掛載的服務端

1.安裝nfs [root@m01 ~]# ansible nfs -m yum -a 'name=nfs-utils state=present'
2.配置nfs [root@m01 ~]# ansible nfs -m copy -a 'content="/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)" dest=/etc/exports'
3.創建用戶 [root@m01 ~]# ansible nfs -m group -a 'name=www gid=666' [root@m01 ~]# ansible nfs -m user -a 'name=www uid=666 group=www shell=/sbin/nologin create_home=no'
4.創建目錄並授權 [root@m01 ~]# ansible nfs -m file -a 'path=/data state=directory owner=www group=www'
5.啟動 [root@m01 ~]# ansible nfs -m systemd -a 'name=nfs state=started'

 

3)客戶端使用模塊掛載

#掛載目錄,並加入開機自動掛載 [root@m01 ~]# ansible web01 -m mount -a 'src=172.16.1.31:/data path=/code/wordpress fstype=nfs state=mounted' #取消掛載,並取消開機自動掛載 [root@m01 ~]# ansible web01 -m mount -a 'src=172.16.1.31:/data path=/code/wordpress fstype=nfs state=absent'

 

 

 

2.selinux模塊

1)幫助語法

EXAMPLES: - name: Enable SELinux selinux: policy: targeted state: enforcing #開啟 disabled #關閉

 

2)關閉selinux

[root@m01 ~]# ansible web01 -m selinux -a 'state=disabled'

 

 

 

3.firewalld模塊

1)幫助語法

EXAMPLES: - firewalld: service: https #防火牆開啟的服務 permanent: #永久生效 yes no state: #臨時生效 enabled #開啟 disable #關閉 port: 8081/tcp  161-162/udp #防火牆配置的端口 zone: dmz #指定配置空間 rich_rule: #富規則 source: 192.0.2.0/24 #防火牆配置的源ip masquerade: yes #開啟ip偽裝 no #關閉ip偽裝 interface: eth2                     #綁定網卡

 

2)防火牆配置實踐

#1.允許訪問http,永久生效 [root@m01 ~]# ansible web01 -m firewalld -a 'service=http permanent=yes state=enabled' #2.允許80端口被訪問,臨時生效 [root@m01 ~]# ansible web01 -m firewalld -a 'port=80/tcp state=enabled' #3.允許10.0.0.0/24網段訪問22端口 [root@m01 ~]# ansible web01 -m firewalld -a 'rich_rule="rule family=ipv4 source address=10.0.0.0/24 service name=ssh accept" state=enabled' #4.允許10.0.0.0/24網段訪問所有服務 [root@m01 ~]# ansible web01 -m firewalld -a 'source=10.0.0.0/24 zone=trusted state=enabled permanent=yes'

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM