北京网站推广外包济南模板建站多少钱
ansible模块学习
copy模块
| copy模块 | |
|---|---|
| src | source 源⽂件 | 
| dest | destination ⽬标 | 
| backup | backup=yes 则会在覆盖前进⾏备份 | 
| mode | 修改权限 | 
| owner | 修改为指定所有者 | 
| group | 修改为指定⽤户组 | 
案例1:传输/root/work/scripts/net-tools-install.sh⽂件到/opt/net-tools-install.sh
ansible all -m copy -a 'src=/root/work/scripts/net-tools-install.sh dest=/opt/net-tools-install.sh'
 
案例2:传输/root/work/scripts/net-tools-install.sh⽂件到/opt/net-tools-install.sh,先备份,后修改
ansible all -m copy  -a 'src=/root/work/scripts/net-tools-install.sh dest=/opt/net-tools-install.sh backup=yes'
 
systemd模块
| systemd模块 | |
|---|---|
| name | ⽤于指定服务名称 | 
| enabled | 控制服务的开机⾃启动 enabled=yes /enabled=no | 
| state | 表示服务开,关,重启… state=started 开启 state=stopped 关闭 state=reloaded 重读配置⽂件(服务⽀持) sshd,nfs state=restarted 重启(关闭再开启)  | 
| daemon-reload | yes是否重新加载对应的服务的管理配置⽂件(讲解了systemctl配置⽂件.) | 
案例1:关闭防火墙
ansible all -m systemd -a 'name=firewalld enabled=no state=stopped'
ansible all -a 'systemctl status firewalld'
 
案例2:开启防火墙
ansible all -m systemd -a 'name=firewalld enabled=yes state=started'
ansible all -a 'systemctl status firewalld'
 
案例3:重启网络服务
ansible all -m systemd -a 'name=network state=restarted'
 
yum模块
通过yum命令安装软件
| yum模块 | |
|---|---|
| name | 指定软件包名字 | 
| state | installed 安装(present) removed 删除 (absent) latest安装或更新  | 
案例1:安装 lrzsz
ansible all -m yum -a 'name=lrzsz state=installed'
 
案例2:安装sl,cowsay, aalib
ansible all -m yum -a 'name=sl,cowsay,aalib state=installed'
 
get_url模块
| get_url下载功能 | |
|---|---|
| url | 指定要下载的地址 | 
| dest | 下载到哪个⽬录 | 
案例1:下载nginx源码包到 /opt目录下
下载地址: https://nginx.org/download/nginx-1.24.0.tar.gz
ansible all -m get_url -a 'url=https://nginx.org/download/nginx-1.24.0.tar.gz dest=/opt'
