Pre-requisite tasks

15 views
Skip to first unread message

Dan Nestor

unread,
Aug 22, 2016, 8:34:59 AM8/22/16
to Ansible Project
Hello everybody, this is my first post here.

I have a playbook that includes these tasks:

- name: Staging directory exists
  file
:
    path
: "{{ staging_dir }}"
    recurse
: yes
    state
: directory


- name: "{{ java_package }} is present in staging directory"
  copy
:
    src
: "{{ java_package }}"
    dest
: "{{ staging_dir }}/{{ java_package }}"


- name: "{{ java_package }} is installed"
  yum
:
    name
: "{{ staging_dir }}/{{ java_package }}"
    state
: present

I would like to copy the file to the host only if needed, that is, the RPM in question is not already installed. Can I do this in Ansible?

Thanks!

Dan

Kai Stian Olstad

unread,
Aug 22, 2016, 9:43:37 AM8/22/16
to ansible...@googlegroups.com
- name: Check if package is installed
command: rpm -q {{ java_package }}
register: package_installed

- block:
- name: Staging directory exists
file:
path: "{{ staging_dir }}"
recurse: yes
state: directory

- name: "{{ java_package }} is present in staging directory"
copy:
src: "{{ java_package }}"
dest: "{{ staging_dir }}/{{ java_package }}"

- name: "{{ java_package }} is installed"
yum:
name: "{{ staging_dir }}/{{ java_package }}"
state: present
when: package_installed.rc == 1

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages