• anible包模块管理


    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 Updating certificate-based repositories. Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.2.15-15.el6 will be installed --> Processing Dependency: httpd-tools = 2.2.15-15.el6 for package: httpd-2.2.15-15.el6.x86_64 --> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-15.el6.x86_64 --> Running transaction check ---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed ---> Package httpd-tools.x86_64 0:2.2.15-15.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package           Arch       Version                Repository            Size ================================================================================ Installing: httpd             x86_64     2.2.15-15.el6          rhel-source-beta     808 k Installing for dependencies: apr-util-ldap     x86_64     1.3.9-3.el6_0.1        rhel-source-beta      15 k httpd-tools       x86_64     2.2.15-15.el6          rhel-source-beta      70 k Transaction Summary ================================================================================ Install       3 Package(s) Total download size: 893 k Installed size: 3.1 M Downloading Packages: -------------------------------------------------------------------------------- Total                                            25 MB/s | 893 kB     00:00     Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction   Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                         1/3   Installing : httpd-tools-2.2.15-15.el6.x86_64                             2/3   Installing : httpd-2.2.15-15.el6.x86_64                                   3/3 Installed products updated. Installed:   httpd.x86_64 0:2.2.15-15.el6                                                  Dependency Installed:   apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1   httpd-tools.x86_64 0:2.2.15-15.el6  Complete! "

        ]

    }

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

    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 Updating certificate-based repositories. Setting up Remove Process Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.2.15-15.el6 will be erased --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package      Arch          Version              Repository                Size ================================================================================ Removing: httpd        x86_64        2.2.15-15.el6        @rhel-source-beta        2.9 M Transaction Summary ================================================================================ Remove        1 Package(s) Installed size: 2.9 M Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction   Erasing    : httpd-2.2.15-15.el6.x86_64                                   1/1 Installed products updated. Removed:   httpd.x86_64 0:2.2.15-15.el6                                                  Complete! "

        ]

    }

    移除安装包

    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 Updating certificate-based repositories. Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.2.15-15.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package         Arch             Version                   Repository     Size ================================================================================ Installing: httpd           x86_64           2.2.15-15.el6             kel           808 k Transaction Summary ================================================================================ Install       1 Package(s) Total download size: 808 k Installed size: 2.9 M Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction   Installing : httpd-2.2.15-15.el6.x86_64                                   1/1 Installed products updated. Installed:   httpd.x86_64 0:2.2.15-15.el6                                                  Complete! "

        ]

    }

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

    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 Updating certificate-based repositories. Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.2.15-15.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package         Arch             Version                   Repository     Size ================================================================================ Installing: httpd           x86_64           2.2.15-15.el6             kel           808 k Transaction Summary ================================================================================ Install       1 Package(s) Total download size: 808 k Installed size: 2.9 M Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction   Installing : httpd-2.2.15-15.el6.x86_64                                   1/1 Installed products updated. Installed:   httpd.x86_64 0:2.2.15-15.el6                                                  Complete! "

        ]

    }

    在进行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"

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

    for linux and python
  • 相关阅读:
    mysql存储过程
    cms初步构想
    ubuntu 搭建Mercurial 服务(nginx)
    ubuntu 搭建简易的https网站
    【分布式】ZooKeeper权限控制之ACL(Access Control List)访问控制列表
    【分布式】Zookeeper的Leader选举-选举过程介绍(经典的Paxos算法解析)
    【Java 泛型】之 <? super T> 和<? extends T> 中 super ,extends如何理解?有何异同?
    CSS3 圆角(border-radius)
    css去除链接 input 虚框
    关于背景色半透明的实现
  • 原文地址:https://www.cnblogs.com/kellyseeme/p/5525084.html
Copyright © 2020-2023  润新知