ansible使用9--包管理模块

包管理模块

yum_repository模块

yum仓库管理
name: required仓库的唯一id,也就是“.repo”配置文件中每个仓库对印的中括号内的仓库ID
baseurl: yum仓库url
description: 仓库注释
file: 设置仓库配置文件名称,xxxx.repo
enabled: 是否激活yum源
gpgcheck: 是否开启包验证
gpgcakey: 指定验证包所需的公钥
state: 默认为present,当值为absent,删除对应的源

示例:

[root@self1-centos7-2 20:50:12 ~]#ansible self1-1 -m yum_repository -a 'name=aliepel description="aliyum" file=aliyum baseurl=https://mirrors.aliyun.com/epel/$releasever\Server/$basearch/'
self1-1 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "repo": "aliepel", 
    "state": "present"
}

yum模块

[root@self1-centos7-2 20:51:10 ~]#ansible-doc -s yum
- name: Manages packages with the `yum' package manager
  yum:
      allow_downgrade:       # Specify if the named package and version is allowed to downgrade a maybe already installed higher version of that
                               package. Note that setting allow_downgrade=True can make this module behave in a non-
                               idempotent way. The task could end up with a set of packages that does not match the
                               complete list of specified packages to install (because dependencies between the
                               downgraded package and others can cause changes to the packages which were in the earlier
                               transaction).
      autoremove:            # If `yes', removes all "leaf" packages from the system that were originally installed as dependencies of user-installed
                               packages but which are no longer required by any such package. Should be used alone or
                               when state is `absent' NOTE: This feature requires yum >= 3.4.3 (RHEL/CentOS 7+)
      bugfix:                # If set to `yes', and `state=latest' then only installs updates that have been marked bugfix related.
      conf_file:             # The remote yum configuration file to use for the transaction.
      disable_excludes:      # Disable the excludes defined in YUM config files. If set to `all', disables all excludes. If set to `main', disable
                               excludes defined in [main] in yum.conf. If set to `repoid', disable excludes defined for
                               given repo id.
      disable_gpg_check:     # 禁用公钥gpg验证'.
      disable_plugin:        # `Plugin' name to disable for the install/update operation. The disabled plugins will not persist beyond the transaction.
      disablerepo:           # 安装包临时禁用的yum源
      download_dir:          # Specifies an alternate directory to store packages. Has an effect only if `download_only' is specified.
      download_only:         # Only download the packages, do not install them.
      enable_plugin:         # `Plugin' name to enable for the install/update operation. The enabled plugin will not persist beyond the transaction.
      enablerepo:            # 指定安装软件包临时启用的yum源
 
      exclude:               # Package name(s) to exclude when state=present, or latest
      install_weak_deps:     # Will also install all packages linked by a weak dependency relation. NOTE: This feature requires yum >= 4 (RHEL/CentOS
                               8+)
      installroot:           # Specifies an alternative installroot, relative to which all packages will be installed.
      list:                  # Package name to run the equivalent of yum list <package> against. In addition to listing packages, use can also list the
                               following: `installed', `updates', `available' and `repos'.
      lock_timeout:          # Amount of time to wait for the yum lockfile to be freed.
      name:                  # 管理的包名.
      releasever:            # Specifies an alternative release from which all packages will be installed.
      security:              # If set to `yes', and `state=latest' then only installs updates that have been marked security related.
      skip_broken:           # Skip packages with broken dependencies(devsolve) and are causing problems.
      state:                 # 指定软件包的状态,默认为present,表示确保安装了程序包 (`present' == `installed', `latest确保最新版本'), or remove (`absent' or `removed') a package. `
      update_cache:          # Force yum to check if cache is out of date and redownload if needed. Has an effect only if state is `present' or
                               `latest'.
      update_only:           # When using latest, only update installed packages. Do not install packages. Has an effect only if state is `latest'
      use_backend:           # This module supports `yum' (as it always has), this is known as `yum3'/`YUM3'/`yum-deprecated' by upstream yum
                               developers. As of Ansible 2.7+, this module also supports `YUM4', which is the "new yum"
                               and it has an `dnf' backend. By default, this module will select the backend based on the
                               `ansible_pkg_mgr' fact.
      validate_certs:        # This only applies if using a https url as the source of the rpm. e.g. for localinstall. If set to `no', the SSL
                               certificates will not be validated. This should only set to `no' used on personally
                               controlled sites using self-signed certificates as it avoids verifying the source site.
                               Prior to 2.1 the code worked as if this was set to `yes'.

示例:使用刚才建的aliepel源安装nginx,三条命令都一样。确保self1-1上有nginx

[root@self1-centos7-2 20:54:15 ~]#ansible self1-1 -m yum -a 'name=nginx disable_gpg_check=yes enablerepo=aliepel'
[root@self1-centos7-2 20:54:15 ~]#ansible self1-1 -m yum -a 'name=nginx state=present disable_gpg_check=yes enablerepo=aliepel'
[root@self1-centos7-2 20:54:15 ~]#ansible self1-1 -m yum -a 'name=nginx state=installed disable_gpg_check=yes enablerepo=aliepel'
self1-1 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": true, 
    "changes": {
        "installed": [
            "nginx"
        ]
    }, 
    "msg": "There are unfinished transactions remaining. You might consider running yum-complete-transaction, or \"yum-complete-transaction --cleanup-only\" and \"yum history redo last\", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).\n", 
    "rc": 0, 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值