Last active
December 16, 2020 09:40
-
-
Save goldyfruit/f4f274be3144e6afca69 to your computer and use it in GitHub Desktop.
[ansible] Check via the yum module and a registered value if a package is installed or not
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
--- | |
- name: Ansible tests playbook | |
hosts: all | |
remote_user: root | |
tasks: | |
- name: Check if mariadb-libs-5.5.44-2.el7.centos.x86_64 package is installed | |
yum: | |
list=mariadb-libs-5.5*x86_64 | |
register: pkg | |
- name: Removing old mariadb-libs package | |
package: | |
name=mariadb-libs | |
state=absent | |
when: ansible_os_family == 'RedHat' and | |
pkg.results[0].yumstate == 'installed' |
the package_facts module maybe better for this.
- package_facts: {}
- when: ansible_facts.packages["mysql57-community-release"] is undefined
block:
- yum:
name: http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
state: present
- yum: {name: mysql-server, state: present}
- service: {name: mysqld, state: started, enabled: yes}
- shell: grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}';
register: result
- .... etc ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@beebird solution is cleanest