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, 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章