每日学习-ansible yum模块

yum模块用于在python2环境下管理基于RPM的Linux发行版中的rpm包,在python3环境中使用dnf模块。

yum模块经常使用参数php

name:必须参数,指定要操做的包名,同时能够指定版本,,若是指定了之前的版本,须要打开allow_downgrade参数;若是state参数为latest,name参数能够指定为'*',这意味着yum -y update;若是指定了本地的rpm文件或是一个url链接,须要state参数为present。
allow_downgrade:是否容许rpm包版本降级(True或False)
state:安装 (present or installed, latest) 或删除 (absent or removed) 包,
download_only:仅下载,不安装
download_dir:与download_only参数一块儿使用,指定下载包的目录
disable_gpg_check:当state参数值为present或latest时,禁用gpg检查
list:列出包的安装,更新,可用以及仓库信息,至关于yum listpython

yum模块示例
一、安装php和mariadbnginx

- name: install php and mariadb
      yum: name= "{{ item }}"
      with_items:
        - php
        - mariadb

二、安装Development Tools包组centos

- name: install Development Tools
  hosts: dev
  tasks:
    - name: install development tools
      yum: name="@Development Tools"

三、升级主机上的软件包到最新版本ide

- name:  update for all
  hosts: dev
  tasks:
    - name: update
      yum: name="*" state=latest

四、移除httpdurl

- name: remove httpd
      yum: name= httpd state=absent

五、升级主机上的软件包到最新版本,除去内核debug

- name: Upgrade  removing the kernel
  hosts: dev
  tasks:
    - name: update
      yum: name="*" state=latest exclude=kernel*

六、从url安装包code

- name: install the nginx rpm from a remote repo
  yum:
    name: http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
    state: present

七、从本地rpm包安装rem

- name: install nginx rpm from a local file
  yum:
    name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
    state: present

八、列出ansible相关的包it

- name: List ansible packages and register result to print with debug later.
  yum:
    list: ansible
  register: result

九、只下载,不安装

- name: Download the nginx package but do not install it
  yum:
    name:
      - nginx
    state: latest
    download_only: true
    download_dir: /root/nginx_rpms/

参考:ansible-doc yum

相关文章
相关标签/搜索