Ansible概述和模块解释(你刚走过了今天,而扑面而来的却是昨天)(三)

简介: Ansible概述和模块解释(你刚走过了今天,而扑面而来的却是昨天)(三)

3.7 file模块


设置文件属性


ansible-doc -s file
#修改文件的属主属组权限等
ansible dbservers -m file -a 'owner=zhangsan group=mysql mode=777 path=/opt/123.txt'  
ansible dbservers -a 'ls -l /opt'
##设置/opt/123.txt.bak 为 /opt/123.txt 的链接文件
ansible dbservers -m file -a 'path=/opt/123.txt.link src=/opt/123.txt state=link'
ansible dbservers -m file -a 'path=/opt/abc.txt state=touch'  #创建一个文件
ansible dbservers -m file -a 'path=/opt/abc.txt state=absent' #删除一个文件


3.7.1 修改属主和属组及权限


3.7.2 创建软链接


3.7.3 创建文件,并删除文件


3.8 hostname 模块


用于管理远程主机上的主机名

ansible dbservers -m hostname -a 'name=testhost'



3.9 ping 模块


ansible all -m ping


3.10 yum 模块


在远程主机上安装与卸载软件包


ansible-doc -s yum
ansible webservers -m yum -a 'name=httpd'      #安装服务
ansible webservers -m yum -a 'name=httpd state=absent'    #卸载服务


3.11 service/systemd 模块


用于在远程主机上管理服务的运行状态


ansible-doc -s service
##常用的参数
name:被管理的服务名称。
state=started | stopped | restarted:动作包含启动关闭或者重启。
enabled=yes | no:表示是否设置该服务开机自启。
runlevel:如果设定了enabled开机自启去,则要定义在哪些运行目标下自启动。
ansible webservers -m service -a 'name=httpd enabled=true state=started'  #安装服务并设为开机自启
systemctl is-enabled  httpd.service   #被控制端查看是否设为开机自启



3.12 script 模块


实现远程批量运行本地 shell 脚本

ansible-doc -s script
vim test.sh      #编写一个脚本
#!/bin/bash
echo "hello ansible from script" > /opt/script.txt  #在script.txt中写入指定内容
chmod +x test.sh            #赋予权限
ansible dbservers -m script -a 'test.sh'    #实现远程运行本地的脚本
ansible dbservers -a 'cat /opt/script.txt'    #查看生成的文档内容


3.13 setup 模块


facts组件是用来收集被管理节点信息的,使用 setup 模块可以获取这些信息


ansible-doc -s setup
ansible webservers -m setup       #获取webservers组主机的facts信息
ansible webservers -m setup -a 'filter=*ipv4'  #使用filter可以筛选指定的facts信息


目录
相关文章
|
7月前
|
运维 Shell Linux
Ansible自动化运维工具之常用模块使用实战(5)
Ansible自动化运维工具之常用模块使用实战(5)
|
9月前
|
网络协议 网络安全
Ansible模块介绍——防火墙模块
Ansible模块介绍——防火墙模块
153 0
|
4天前
|
算法 安全 Linux
Ansible 中的copy 复制模块应用详解
Ansible 中的copy 复制模块应用详解
|
7月前
|
运维 Linux
Ansible自动化运维工具之常用模块使用实战(6)
Ansible自动化运维工具之常用模块使用实战(6)
|
6月前
|
网络安全 数据安全/隐私保护
ansible的get_url模块
ansible的get_url模块
|
6月前
|
存储 Linux Python
ansible手动添加模块
ansible手动添加模块
50 0
|
9月前
Ansible模块管理——磁盘管理模块、mount模块
Ansible模块管理——磁盘管理模块、mount模块
263 0
|
9月前
|
网络协议 网络安全 数据安全/隐私保护
Ansible模块介绍——配置网络模块、上传下载文件模块
Ansible模块介绍——配置网络模块、上传下载文件模块
275 0
|
9月前
|
应用服务中间件 nginx
Ansible模块——软件包管理模块
Ansible模块——软件包管理模块
|
9月前
|
数据安全/隐私保护 Python
Ansible模块介绍——用户管理模块
Ansible模块介绍——用户管理模块