ansible使用包管理模块

一般使用的包管理模块的RPM,和YUM

参数

必填

默认

选择

说明

Conf_file

No

YUM的配置文件

Disable_dbg_check

No

No

Yes/no

是否开启验证

Disablerepo

No

禁用的仓库

Enablerepo

No

启用的仓库

List

No

非幂等性命令

Name

Yes

包名称

State

No

Present

Present/installed

Latest/absent

Removed

是否插入(present,installed,latest),移除

(absent/removed)包

1.1 安装最新的包

[root@ansibleserver tmp]# ansible pythonserver -m yum -a "name=httpd state=latest"

SSH password:

192.168.1.60 | success >> {

"changed": true,

"msg": "",

"rc": 0,

"results": [

"Loaded plugins: product-id, security, subscription-manager\nUpdating certificate-based repositories.\nSetting up Install Process\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.15-15.el6 will be installed\n-->
Processing Dependency: httpd-tools = 2.2.15-15.el6 for package: httpd-2.2.15-15.el6.x86_64\n--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-15.el6.x86_64\n--> Running transaction check\n---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1
will be installed\n---> Package httpd-tools.x86_64 0:2.2.15-15.el6 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package           Arch      
Version                Repository            Size\n================================================================================\nInstalling:\n httpd             x86_64     2.2.15-15.el6          rhel-source-beta     808 k\nInstalling for dependencies:\n
apr-util-ldap     x86_64     1.3.9-3.el6_0.1        rhel-source-beta      15 k\n httpd-tools       x86_64     2.2.15-15.el6          rhel-source-beta      70 k\n\nTransaction Summary\n================================================================================\nInstall      
3 Package(s)\n\nTotal download size: 893 k\nInstalled size: 3.1 M\nDownloading Packages:\n--------------------------------------------------------------------------------\nTotal                                            25 MB/s | 893 kB     00:00     \nRunning
rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r  Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                         1/3 \n\r  Installing : httpd-tools-2.2.15-15.el6.x86_64                             2/3
\n\r  Installing : httpd-2.2.15-15.el6.x86_64                                   3/3 \nInstalled products updated.\n\nInstalled:\n  httpd.x86_64 0:2.2.15-15.el6                                                  \n\nDependency Installed:\n  apr-util-ldap.x86_64
0:1.3.9-3.el6_0.1   httpd-tools.x86_64 0:2.2.15-15.el6  \n\nComplete!\n"

]

}

查询之后发现已经安装,并且安装了最新版本

name表示需要安装的包名称,state为lastest,表示安装Apache的最新版本

1.2 移除包

[root@ansibleserver tmp]# ansible pythonserver -m yum -a "name=httpd state=absent"

SSH password:

192.168.1.60 | success >> {

"changed": true,

"msg": "",

"rc": 0,

"results": [

"Loaded plugins: product-id, security, subscription-manager\nUpdating certificate-based repositories.\nSetting up Remove Process\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.15-15.el6 will be erased\n-->
Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package      Arch          Version              Repository                Size\n================================================================================\nRemoving:\n
httpd        x86_64        2.2.15-15.el6        @rhel-source-beta        2.9 M\n\nTransaction Summary\n================================================================================\nRemove        1 Package(s)\n\nInstalled size: 2.9 M\nDownloading Packages:\nRunning
rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r  Erasing    : httpd-2.2.15-15.el6.x86_64                                   1/1 \nInstalled products updated.\n\nRemoved:\n  httpd.x86_64 0:2.2.15-15.el6                                                 
\n\nComplete!\n"

]

}

移除安装包

1.3 指定repo来进行安装包

[root@ansibleserver tmp]# ansible pythonserver -m yum -a "name=httpd enablerepo=rhel state=present"

SSH password:

192.168.1.60 | FAILED >> {

"failed": true,

"msg": "Error setting/accessing repo rhel: Error getting repository data for rhel, repository not found"

}

在指定源的时候,使用enablerepo,注意这个名字是配置文件/etc/yum.repo.d/目录中文件的section的名称,如下所示:

[root@ansibleserver yum.repos.d]# cat rhel-source.repo |grep kel

[kel]

name=kel

baseurl=file:///tmp/kel

主要的就是使用这个repo的名字,section为[kel]

在上面的报错信息中,主要就是没有找到这个section

[root@ansibleserver ~]# ansible pythonserver -m yum -a "name=httpd enablerepo=kel state=present"

SSH password:

192.168.1.60 | success >> {

"changed": true,

"msg": "",

"rc": 0,

"results": [

"Loaded plugins: product-id, security, subscription-manager\nUpdating certificate-based repositories.\nSetting up Install Process\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.15-15.el6 will be installed\n-->
Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package         Arch             Version                   Repository     Size\n================================================================================\nInstalling:\n
httpd           x86_64           2.2.15-15.el6             kel           808 k\n\nTransaction Summary\n================================================================================\nInstall       1 Package(s)\n\nTotal download size: 808 k\nInstalled size:
2.9 M\nDownloading Packages:\nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r  Installing : httpd-2.2.15-15.el6.x86_64                                   1/1 \nInstalled products updated.\n\nInstalled:\n 
httpd.x86_64 0:2.2.15-15.el6                                                  \n\nComplete!\n"

]

}

在上面例子中,可以看到直接进行了安装

1.4 指定版本进行安装包

[root@ansibleserver ~]# ansible pythonserver -m yum -a "name=httpd-2.2.15-15.el6.x86_64  state=present "

SSH password:

192.168.1.60 | success >> {

"changed": true,

"msg": "",

"rc": 0,

"results": [

"Loaded plugins: product-id, security, subscription-manager\nUpdating certificate-based repositories.\nSetting up Install Process\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.15-15.el6 will be installed\n-->
Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package         Arch             Version                   Repository     Size\n================================================================================\nInstalling:\n
httpd           x86_64           2.2.15-15.el6             kel           808 k\n\nTransaction Summary\n================================================================================\nInstall       1 Package(s)\n\nTotal download size: 808 k\nInstalled size:
2.9 M\nDownloading Packages:\nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r  Installing : httpd-2.2.15-15.el6.x86_64                                   1/1 \nInstalled products updated.\n\nInstalled:\n 
httpd.x86_64 0:2.2.15-15.el6                                                  \n\nComplete!\n"

]

}

在进行name指定版本的时候,架构类型可以写也可以不写,也就是x86_64可以写或者不写都是可以的

在写上版本的时候,注意是l还是1,注意具体的版本型号,在实验的时候因为字母l和数字1导致很多时间被浪费,指定的具体版本无法进行安装

1.5 更新所有安装包

[root@ansibleserver ~]# ansible pythonserver -m yum -a "name=* state=latest"

1.6 指定rpm进行安装

[root@ansibleserver ~]# ansible pythonserver -m yum -a "name=/usr/local/src/kel.noarch.rpm state=present"

表示直接指定了一个rpm的位置,然后进行直接安装rpm

1.7 指定远程网址rpm进行安装

ansible pythonserver -m yum -a "name=http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6.0.el6.ngx.noarch.rpm  state=present"

直接指定一个远程网址来进行安装包

anible包模块管理的更多相关文章

  1. day17跨文件夹导入模块,模块的两种被执行方式,包,直接使用包中模块,包的管理

    复习 ''' 1.模块 -- 一系列功能的集合体,用文件来管理一系列有联系的功能,该文件我们称之为模块,文件名就是模块名 -- import | from...import 来导入模块,从而使用模块中 ...

  2. Python科学计算包模块的安装(ubuntu)

    Python的科学计算包设计到C语言代码的编译,采用pip的方式安装会出现错误. 一种简单的方式是采用的集成包,具体的步骤参考:https://www.continuum.io/downloads#_ ...

  3. [20150522]RPM包的管理

    RPM包的管理 RPM包的分类 RPM包可分为源码包和二进制包两类.源码包的主要优点是开源,如果有足够的能力,可以修改源代码,源码包可以自由选择所需要安装的功能,软件是编译安装,所以更加适合自己的系统 ...

  4. Webpack: 为Web开发而生的模块管理器[转]

    Webpack: 为Web开发而生的模块管理器 原文地址:http://hanjianwei.com/2014/09/10/webpack-package-manager-for-web/ 10 Se ...

  5. npm模块管理器入门

    什么是 NPM npm 是 Node 官方提供的包管理工具,他已经成了 Node 包的标准发布平台,用于 Node 包的发布.传播.依赖控制.npm 提供了命令行工具,使你可以方便地下载.安装.升级. ...

  6. Perl模块管理

    Perl模块管理 perl有自带的模块,还有第三方模块.自带的模块是随perl安装而安装好的,第三方模块需要从CPAN(Comprehensive Perl Archive Network)上下载并安 ...

  7. [Web 前端] 使用yarn代替npm作为node.js的模块管理器

    cp from : https://www.jianshu.com/p/bfe96f89da0e     Fast, reliable, and secure dependency managemen ...

  8. 每天记录一点:NetCore获得配置文件 appsettings.json vue-router页面传值及接收值 详解webpack + vue + node 打造单页面(入门篇) 30分钟手把手教你学webpack实战 vue.js+webpack模块管理及组件开发

    每天记录一点:NetCore获得配置文件 appsettings.json   用NetCore做项目如果用EF  ORM在网上有很多的配置连接字符串,读取以及使用方法 由于很多朋友用的其他ORM如S ...

  9. 使用yarn代替npm作为node.js的模块管理器

    使用yarn代替npm作为node.js的模块管理器 转 https://www.jianshu.com/p/bfe96f89da0e     Fast, reliable, and secure d ...

随机推荐

  1. 使用RPM管理软件包

    一.概念简介 RPM 全名是『 RedHat Package Manager 』简称则为 RPM,是以一种数据库记录的方式来将你所需要的套件安装到你的 Linux 主机的一套管理程序. 二.实验环境 ...

  2. Oracle临时表(Temporary Table)

    GLOBAL TEMPORARY代表全局临时表临时表的元数据存储在数据字典里面 只当第一条DML命令发生的时候才为这张表的段分配空间 临时表数据的可见范围应该是会话级别或是事务级别的 会话或者事务级别 ...

  3. Centos 7下安装Oracle 12c

    SQL Server玩了有些年,最近想玩玩Oracle,于是想到装一台Oracle server来玩玩.第一次在Linux下安装Oracle,整个过程参考了一篇文章:http://blog.csdn. ...

  4. mysql代码里面有中文注释导致语法错误

    一个简单的创建表的代码 DROP database IF exists reg_login; CREATE database reg_login; use reg_login --用户表 create ...

  5. c++异常 连续抛出异常

      今天天遇到这样一个问题,连续两次抛出异常,但是只有一个catch,会导致core这个时候会导致core, 单线程编程中可能很少遇到这样的问题,但是多线程中是很容易遇到的, 举个例子:catch代码 ...

  6. asp存储过程

    dim s_ip,MyComm s_ip=request.ServerVariables("REMOTE_ADDR") Set MyComm = Server.CreateObje ...

  7. 安卓发展史以及安卓和苹果对比PPT

    此PPT由我们小组协力完成,介绍了Android的发展史以及android与苹果的一些比较.概述了android发展至今的一系列版本,功能的日益完善,它的强大性,灵活性,公开性使其拥有吸引客服的绝大魅 ...

  8. Ubuntu12.04安装YouCompleteMe插件

    以前用的都是ctags+omnicomplete+acp的方式,这次换成clang自解析的方式尝试一把. 自从知道了Vundle,妈妈再也不用担心我麻烦地下插件了 0. 安装必要组件 sudo apt ...

  9. java中时间的获取(二)

    java中时间的获取2 /** * 获取数据库操作记录时间 */ public static String getOpreateDbTime() { Calendar c = Calendar.get ...

  10. HeadFirst Jsp 04 (请求和响应作为servlet)

    servlet 的存在就是为了客服服务, servlet的任务是得到一个客户的请求, 再发回一个响应. 由上图可知, web 容器会在启动后就加载所有的servlet类, 并为之创建实例和初始化 注意 ...