Replace grep and which commands with find module
For improved idempotence within the role, replace the use of `grep` and `which` through the 'command' module with the 'find' module. changed_when and failed_when statements around these tasks can be removed. Partial-Bug: 1640134 Partial-Bug: 1640144 Change-Id: Iebbcd52f673dba657117ac21ef1fa809bf344521
This commit is contained in:
parent
59dd7da206
commit
22b7d9c761
@ -57,19 +57,20 @@
|
||||
# They're only required during upgrades transitioning to a
|
||||
# statically named apt sources file.
|
||||
- name: Find old sources
|
||||
command: >
|
||||
grep -rnil maria /etc/apt/sources.list.d/ --exclude {{ mariadb_repo_filename }}.list
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
find:
|
||||
path: "/etc/apt/sources.list.d/"
|
||||
patterns: "^(?!{{ mariadb_repo_filename }})(.+)|(.+)(?<!{{ mariadb_repo_filename }})\\.list$"
|
||||
contains: "^.*maria.*$"
|
||||
use_regex: true
|
||||
register: old_sources
|
||||
tags:
|
||||
- galera-client-repos
|
||||
|
||||
- name: Remove old sources
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
path: "{{ item.path }}"
|
||||
state: absent
|
||||
with_items: "{{ old_sources.stdout_lines | default([]) }}"
|
||||
with_items: "{{ old_sources.files | default([]) }}"
|
||||
tags:
|
||||
- galera-client-repos
|
||||
|
||||
|
@ -37,14 +37,18 @@
|
||||
galera_client_drop_config_file: false
|
||||
post_tasks:
|
||||
- name: Check that the mysql command is present
|
||||
command: which mysql
|
||||
find:
|
||||
paths: "{{ ansible_env.PATH | regex_replace(':',',') }}"
|
||||
patterns: "mysql"
|
||||
register: mysql
|
||||
- name: Check .my.cnf existence
|
||||
stat:
|
||||
path: /root/.my.cnf
|
||||
register: mycnf
|
||||
- name: Client config file .my.cnf should not exist
|
||||
- name: mysql command should exist and client config file .my.cnf should not
|
||||
assert:
|
||||
that:
|
||||
- "mysql.matched > 0"
|
||||
- "not mycnf.stat.exists"
|
||||
|
||||
- name: Playbook for role testing
|
||||
@ -69,12 +73,16 @@
|
||||
galera_client_drop_config_file: true
|
||||
post_tasks:
|
||||
- name: Check that the mysql command is present
|
||||
command: which mysql
|
||||
find:
|
||||
paths: "{{ ansible_env.PATH | regex_replace(':',',') }}"
|
||||
patterns: "mysql"
|
||||
register: mysql
|
||||
- name: Check .my.cnf existence
|
||||
stat:
|
||||
path: /root/.my.cnf
|
||||
register: mycnf
|
||||
- name: Client config file .my.cnf should exist
|
||||
- name: mysql command and client config file .my.cnf should exist
|
||||
assert:
|
||||
that:
|
||||
- "mysql.matched > 0"
|
||||
- "mycnf.stat.exists"
|
||||
|
Loading…
Reference in New Issue
Block a user