postgresql_idx: revert PR for 64138 (#66889)
This commit is contained in:
parent
4752547d35
commit
308723c3ca
3 changed files with 4 additions and 98 deletions
|
@ -1,2 +0,0 @@
|
||||||
minor_changes:
|
|
||||||
- postgresql_idx - add a new option ``stat`` to the ``state`` parameter (https://github.com/ansible/ansible/pull/64138).
|
|
|
@ -51,13 +51,9 @@ options:
|
||||||
- Index state.
|
- Index state.
|
||||||
- C(present) implies the index will be created if it does not exist.
|
- C(present) implies the index will be created if it does not exist.
|
||||||
- C(absent) implies the index will be dropped if it exists.
|
- C(absent) implies the index will be dropped if it exists.
|
||||||
- C(stat) returns index statistics information from the ``pg_stat_user_indexes`` standard view.
|
|
||||||
Supported from Ansible 2.10.
|
|
||||||
- "When C(stat) following parameters will be ignored:"
|
|
||||||
- I(schema), I(table), I(columns), I(cond), I(idxtype), I(tablespace), I(concurrent), I(cascade).
|
|
||||||
type: str
|
type: str
|
||||||
default: present
|
default: present
|
||||||
choices: [ absent, present, stat ]
|
choices: [ absent, present ]
|
||||||
table:
|
table:
|
||||||
description:
|
description:
|
||||||
- Table to create index on it.
|
- Table to create index on it.
|
||||||
|
@ -207,12 +203,6 @@ EXAMPLES = r'''
|
||||||
idxname: test_idx
|
idxname: test_idx
|
||||||
cond: id > 1
|
cond: id > 1
|
||||||
|
|
||||||
- name: Get index statistics of test_idx from mydb
|
|
||||||
postgresql_idx:
|
|
||||||
db: mydb
|
|
||||||
idxname: test_idx
|
|
||||||
state: stat
|
|
||||||
|
|
||||||
- name: Create unique btree index if not exists test_unique_idx on column name of table products
|
- name: Create unique btree index if not exists test_unique_idx on column name of table products
|
||||||
postgresql_idx:
|
postgresql_idx:
|
||||||
db: acme
|
db: acme
|
||||||
|
@ -259,11 +249,6 @@ valid:
|
||||||
returned: always
|
returned: always
|
||||||
type: bool
|
type: bool
|
||||||
sample: true
|
sample: true
|
||||||
stat:
|
|
||||||
description: Index statistics.
|
|
||||||
returned: if state is stat
|
|
||||||
type: bool
|
|
||||||
sample: { 'idx_scan': 19239, 'idx_tup_read': 929329, 'idx_tup_fetch': 4949459 }
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -344,22 +329,6 @@ class Index(object):
|
||||||
self.__exists_in_db()
|
self.__exists_in_db()
|
||||||
return self.info
|
return self.info
|
||||||
|
|
||||||
def get_stat(self):
|
|
||||||
"""Get and return index statistics.
|
|
||||||
|
|
||||||
Return index statistics dictionary if index exists, otherwise False.
|
|
||||||
"""
|
|
||||||
query = ("SELECT * FROM pg_stat_user_indexes "
|
|
||||||
"WHERE indexrelname = %(name)s "
|
|
||||||
"AND schemaname = %(schema)s")
|
|
||||||
|
|
||||||
result = exec_sql(self, query, query_params={'name': self.name, 'schema': self.schema},
|
|
||||||
add_to_executed=False)
|
|
||||||
if result:
|
|
||||||
return [dict(row) for row in result]
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def __exists_in_db(self):
|
def __exists_in_db(self):
|
||||||
"""Check index existence, collect info, add it to self.info dict.
|
"""Check index existence, collect info, add it to self.info dict.
|
||||||
|
|
||||||
|
@ -495,7 +464,7 @@ def main():
|
||||||
argument_spec.update(
|
argument_spec.update(
|
||||||
idxname=dict(type='str', required=True, aliases=['name']),
|
idxname=dict(type='str', required=True, aliases=['name']),
|
||||||
db=dict(type='str', aliases=['login_db']),
|
db=dict(type='str', aliases=['login_db']),
|
||||||
state=dict(type='str', default='present', choices=['absent', 'present', 'stat']),
|
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||||
concurrent=dict(type='bool', default=True),
|
concurrent=dict(type='bool', default=True),
|
||||||
unique=dict(type='bool', default=False),
|
unique=dict(type='bool', default=False),
|
||||||
table=dict(type='str'),
|
table=dict(type='str'),
|
||||||
|
@ -561,14 +530,7 @@ def main():
|
||||||
#
|
#
|
||||||
# check_mode start
|
# check_mode start
|
||||||
if module.check_mode:
|
if module.check_mode:
|
||||||
if state == 'stat':
|
if state == 'present' and index.exists:
|
||||||
if index.exists:
|
|
||||||
kw['stat'] = index.get_stat()
|
|
||||||
|
|
||||||
kw['changed'] = False
|
|
||||||
module.exit_json(**kw)
|
|
||||||
|
|
||||||
elif state == 'present' and index.exists:
|
|
||||||
kw['changed'] = False
|
kw['changed'] = False
|
||||||
module.exit_json(**kw)
|
module.exit_json(**kw)
|
||||||
|
|
||||||
|
@ -586,14 +548,7 @@ def main():
|
||||||
# check_mode end
|
# check_mode end
|
||||||
#
|
#
|
||||||
|
|
||||||
if state == 'stat':
|
if state == "present":
|
||||||
if index.exists:
|
|
||||||
kw['stat'] = index.get_stat()
|
|
||||||
|
|
||||||
kw['changed'] = False
|
|
||||||
module.exit_json(**kw)
|
|
||||||
|
|
||||||
elif state == "present":
|
|
||||||
if idxtype and idxtype.upper() not in VALID_IDX_TYPES:
|
if idxtype and idxtype.upper() not in VALID_IDX_TYPES:
|
||||||
module.fail_json(msg="Index type '%s' of %s is not in valid types" % (idxtype, idxname))
|
module.fail_json(msg="Index type '%s' of %s is not in valid types" % (idxtype, idxname))
|
||||||
|
|
||||||
|
|
|
@ -298,53 +298,6 @@
|
||||||
- result is not changed
|
- result is not changed
|
||||||
- result.msg == 'Only btree currently supports unique indexes'
|
- result.msg == 'Only btree currently supports unique indexes'
|
||||||
|
|
||||||
# Get idx stat in check mode
|
|
||||||
- name: postgresql_idx - test state stat in check_mode
|
|
||||||
become_user: "{{ pg_user }}"
|
|
||||||
become: yes
|
|
||||||
postgresql_idx:
|
|
||||||
db: postgres
|
|
||||||
login_user: "{{ pg_user }}"
|
|
||||||
idxname: test1_idx
|
|
||||||
state: stat
|
|
||||||
check_mode: yes
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- result is not changed
|
|
||||||
- result.tblname == 'test_table'
|
|
||||||
- result.name == 'test1_idx'
|
|
||||||
- result.state == 'present'
|
|
||||||
- result.valid != ''
|
|
||||||
- result.tblspace == ''
|
|
||||||
- result.storage_params == []
|
|
||||||
- result.schema == 'public'
|
|
||||||
- result.stat != {}
|
|
||||||
|
|
||||||
# Get idx stat
|
|
||||||
- name: postgresql_idx - test state stat
|
|
||||||
become_user: "{{ pg_user }}"
|
|
||||||
become: yes
|
|
||||||
postgresql_idx:
|
|
||||||
db: postgres
|
|
||||||
login_user: "{{ pg_user }}"
|
|
||||||
idxname: test1_idx
|
|
||||||
state: stat
|
|
||||||
register: result
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- result is not changed
|
|
||||||
- result.tblname == 'test_table'
|
|
||||||
- result.name == 'test1_idx'
|
|
||||||
- result.state == 'present'
|
|
||||||
- result.valid != ''
|
|
||||||
- result.tblspace == ''
|
|
||||||
- result.storage_params == []
|
|
||||||
- result.schema == 'public'
|
|
||||||
- result.stat != {}
|
|
||||||
|
|
||||||
# Drop index from specific schema with cascade in check_mode
|
# Drop index from specific schema with cascade in check_mode
|
||||||
- name: postgresql_idx - drop index from specific schema cascade in check_mode
|
- name: postgresql_idx - drop index from specific schema cascade in check_mode
|
||||||
become_user: "{{ pg_user }}"
|
become_user: "{{ pg_user }}"
|
||||||
|
|
Loading…
Reference in a new issue