ansible模块专项练习题

file模块

  • 该模块的关键字有 path被控主机端的路径 、state 状态 、 touch创建文件 、 directory 创建目录、 recures 递归 、owner 所属主、 group所属组、 mode 权限。

1.创建文件,并且设定属主,属组,权限

[root@localhost opt]# ansible dbserver -m file -a "path=/var/www/html/xjm.html state=touch owner=root group=root mode=644" -i hosts 

2.创建目录,并设定属主,属组,权限

[root@localhost opt]# ansible dbserver -m file -a "path=/var/www/html/dd state=directory owner=root group=root mode=755" -i hosts 

3.递归授权目录的方式

[root@localhost opt]# ansible dbserver -m file -a "path=/var/www/html/ owner=apache group=apache recurse=yes" -i hosts  

把/var/www/html目录下的所有目录和文件的所属主和所属组都改为apache
在这里插入图片描述

yum模块

  • 该模块的主要参数有:name:要安装的软件包名,多个软件包以英文逗号隔开, state 对当前指定的软件安装、移除操作 支持的参数有:
    present:确认已经安装,但不升级
    inistalled:确认已经安装
    latest:确保安装,且升级为最新
    absent和removed:确认已移除
    exclude :排除

1.安装当前最新的apache软件,如果存在就更新

[root@localhost opt]# ansible dbserver -m yum -a "name=httpd state=latest" -i hosts 

2.安装当前最新的apache,通过epel仓库安装

[root@localhost opt]# ansible dbserver -m yum -a "name=httpd state=latest enablerepo=epel" -i hosts 

3.通过公网url安装rpm软件

[root@localhost opt]# ansible dbserver -m yum -a "name=http://nginx.org/packages/rhel/7/x86_64/RPMS/nginx-1.10.0-1.el7.ngx.x86_64.rpm state=latest" -i hosts

在这里插入图片描述

4.更新所有的软件包,但是排除kernel相关的软件包

[root@localhost opt]# ansible dbserver -m yum -a "name=* state=latest exclude=kernel*" -i hosts 

要排除多个,用逗号隔开

在这里插入图片描述

5.删除apache软件

[root@localhost opt]# ansbile dbserver -m yum -a "name=httpd state=absent" -i hosts

copy模块

  • copy模块的参数有:
  • src:指定拷贝文件的源地址
    dest:指定拷贝文件的目标地址
    backup:拷贝文件前,若原始文件发生变化,则对目标文件进行备份
    owner:指定新拷贝文件的所有者
    group:指定新拷贝文件的所有组
    mode:指定新拷贝文件的权限

1.将本地的httpd.conf文件listen端口修改为8080,然后推送到远端服务

[root@localhost opt]# ansible dbserver -m copy -a "src=/opt/xjm/http.conf dest=/opt/xjm/httpd.conf owner=root group=root mode=644" -i hosts 

2.将本地的httpd.conf文件listen端口修改为9090。然后推送到远端,检查远端是否存在上一次的备份

[root@localhost opt]# ansible dbserver -m copy 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值