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:
Jimmy McCrory 2017-02-14 10:57:09 -08:00
parent 59dd7da206
commit 22b7d9c761
2 changed files with 19 additions and 10 deletions

View File

@ -57,19 +57,20 @@
# They're only required during upgrades transitioning to a # They're only required during upgrades transitioning to a
# statically named apt sources file. # statically named apt sources file.
- name: Find old sources - name: Find old sources
command: > find:
grep -rnil maria /etc/apt/sources.list.d/ --exclude {{ mariadb_repo_filename }}.list path: "/etc/apt/sources.list.d/"
changed_when: false patterns: "^(?!{{ mariadb_repo_filename }})(.+)|(.+)(?<!{{ mariadb_repo_filename }})\\.list$"
failed_when: false contains: "^.*maria.*$"
use_regex: true
register: old_sources register: old_sources
tags: tags:
- galera-client-repos - galera-client-repos
- name: Remove old sources - name: Remove old sources
file: file:
path: "{{ item }}" path: "{{ item.path }}"
state: absent state: absent
with_items: "{{ old_sources.stdout_lines | default([]) }}" with_items: "{{ old_sources.files | default([]) }}"
tags: tags:
- galera-client-repos - galera-client-repos

View File

@ -37,14 +37,18 @@
galera_client_drop_config_file: false galera_client_drop_config_file: false
post_tasks: post_tasks:
- name: Check that the mysql command is present - 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 - name: Check .my.cnf existence
stat: stat:
path: /root/.my.cnf path: /root/.my.cnf
register: mycnf 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: assert:
that: that:
- "mysql.matched > 0"
- "not mycnf.stat.exists" - "not mycnf.stat.exists"
- name: Playbook for role testing - name: Playbook for role testing
@ -69,12 +73,16 @@
galera_client_drop_config_file: true galera_client_drop_config_file: true
post_tasks: post_tasks:
- name: Check that the mysql command is present - 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 - name: Check .my.cnf existence
stat: stat:
path: /root/.my.cnf path: /root/.my.cnf
register: mycnf register: mycnf
- name: Client config file .my.cnf should exist - name: mysql command and client config file .my.cnf should exist
assert: assert:
that: that:
- "mysql.matched > 0"
- "mycnf.stat.exists" - "mycnf.stat.exists"