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 #取消临时挂载,并且清理自动挂载(常用)
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'
#挂载目录,并加入开机自动挂载 [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'
EXAMPLES: - name: Enable SELinux selinux: policy: targeted state: enforcing #开启 disabled #关闭
[root@m01 ~]# ansible web01 -m selinux -a 'state=disabled'
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 #绑定网卡
#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'