每日學習-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

相關文章
相關標籤/搜索