使用ansible离线安装rpm包

首先利用copy模块将包分发至目标机器
命令方式

ansible  cloud  -m copy -a "src=telnet-0.17-66.el7.x86_64.rpm dest=/tmp/"

playbook

---
- hosts: cloud
  tasks:
  - name: Copy file with owner and permissions
    copy:
      src: /srv/myfiles/nginx-release-centos-6-0.el6.ngx.noarch.rpm
      dest: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm

使用ansible yum 模块离线安装

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

扩展:
针对有依赖的包,我们需要一起安装

---
- hosts: cloud
  tasks:
  - name: ensure a list of packages installed
    yum:
      name: "{{ packages }}"
    vars:
      packages:
      - httpd
      - httpd-tools

安装离线包配置如下:

- name: ensure a list of packages installed
  yum:
    name: "{{ packages }}"
  vars:
    packages:
    - /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm
    - /usr/local/src/依赖.ngx.noarch.rpm

你可能感兴趣的:(ansible,ansible,离线安装)