Created
May 22, 2017 01:03
-
-
Save zdyxry/a8a2123b2a3dbdf0948df121f657803f to your computer and use it in GitHub Desktop.
Check if some rpm is installed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.