Skip to content

Instantly share code, notes, and snippets.

@zdyxry
Created May 22, 2017 01:03
Show Gist options
  • Save zdyxry/a8a2123b2a3dbdf0948df121f657803f to your computer and use it in GitHub Desktop.
Save zdyxry/a8a2123b2a3dbdf0948df121f657803f to your computer and use it in GitHub Desktop.
Check if some rpm is installed
#!/usr/bin/env ansible-playbook
---
- name: rpm_check
hosts: test_vm
tasks:
- name: copy the_silver_searcher rpm
copy: src=/opt/the_silver_searcher-0.33.0-1.el7.x86_64.rpm dest=/opt/the_silver_searcher-0.33.0-1.el7.x86_64.rpm
- name: Check if ag.rpm is installed
command: rpm -q the_silver_searcher
register: rpm_check
failed_when: rpm_check.rc > 1
changed_when: no
- debug: var=rpm_check
- name: install ag.rpm (the_silver_searcher)
raw: yum install -y /opt/the_silver_searcher-0.33.0-1.el7.x86_64.rpm
register: out
when: rpm_check.rc != 0
- debug: var=out.stdout_lines
@zdyxry
Copy link
Author

zdyxry commented May 22, 2017

Suppose the error code of a command is meaningless and to tell if there is a failure what really matters is the output of the command, for instance if the string “FAILED” is in the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment