商务网站建设的调研,购物网站模板下载,网站建设合理的流程,做网站打广告1.Ansible模块
作用:通过ansible模块实现批量管理 2.command模块与shell模块
command模块是ansible默认的模块#xff0c;适用于执行简单的命令#xff0c;不支持特殊符号
案列01#xff0c;批量获取主机名
ansible all -m command -a hostname
all表示对主机清单所有组…1.Ansible模块
作用:通过ansible模块实现批量管理 2.command模块与shell模块
command模块是ansible默认的模块适用于执行简单的命令不支持特殊符号
案列01批量获取主机名
ansible all -m command -a hostname
all表示对主机清单所有组进行操作-m command表示使用command模块默认是此模块-a指定模块中的选项。
shell模块相比command可以识别特殊符号
案列02删除/tmp目录下的所有文件
ansible all -m shell -a rm -rf /tmp/* 3.script模块
执行流程分发脚本在被管理端执行脚本
案例03被管理端执行指定目录下的脚本
ansible all -m script -a /server/scripts/ansible-scripts.sh 4.file模块
管理文件目录软链接
相关选项
path 路径目录文件必须要写
state statedirectory 创建目录 statefile 默认更新文件文件不存在也不创建 statelink 创建软连接 statetouch 创建文件 stateabsent 删除
mode mode755 创建并修改权限
owner ownerroot
group grouproot
案例03所有被管理端的/tmp目录下创建day021.txt
ansible all -m file -a path/tmp/day021.txt statetouch
案例04将/tmp目录下的day021.txt新建软连接到tmpls目录中
ansible all -m file -a src/tmp/day021.txt path/tmpls/day021.txt statelink 5.copy模块
相关选项
src 管理端源文件
dest 被管理端目录/文件
backup backupyes会在覆盖前备份
mode 修改权限
owner 修改为指定所有者
group 修改为指定用户组
案例05将管理端hosts文件发送给被管理端/tmp/day021/的目录下
ansible all -m copy -a src/etc/hosts dest/tmp/day021/ 5.systemd模块
name 用于指定服务名称
enabled yes开机自启动
state started 开启 stopped 关闭 reloaded 重载 restarted 重启
daemon-reload yes是否重新加载对应服务的管理配置文件 6.yum模块
包含了yum和apt
name 指定软件包名字
state installed安装 removed删除 lastest安装或更新
update_cache 更新本地yum缓存 7.get_url模块
url 指定要下载的地址
dest 下载到哪一个目录
后续可以调用yum模块安装本地的软件 name/app/tools/xxxxx.rpm即可 8.user模块
name 用户名
uid 指定uid
group 指定用户组
shell 指定解释器
crete_home yes/no是否创建用户家目录
state present添加absent(删除)
password 加密的密码
更新密码
ansible all -m user -a name用户名 password{{ 新密码 | password_hash(sha512, 加密字符串) }} statepresent 9.mount模块
实现mount命令进行挂载同时修改/etc/fstab进行永久挂载
fstype 指定文件系统
src 源地址挂载nfs,eg 172.16.1.31:/data
path 挂载点
state mounted,挂载并修改fstab absent,卸载并修改fstab unmounted卸载但不修改fstab present仅修改fstab,不挂载 10.cron模块
-name 定时任务名字对应注释内容
minute 分钟 minute*/2
hour 默认*
day
month
week
job 脚本位置
state present添加absent删除
将时间同步写到定时任务每五分钟同步一次
ansible all -m cron -a namesync_time minute*/5 job/usr/sbin/ntpdate ntp1.aliyun.com /dev/null statepresent
结果