mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-27 12:51:25 -07:00
Switch tests from sudo to become. (#17694)
This commit is contained in:
parent
23651b657e
commit
39c5c558f8
9 changed files with 157 additions and 157 deletions
|
@ -24,7 +24,7 @@
|
||||||
- hosts: ec2
|
- hosts: ec2
|
||||||
gather_facts: no
|
gather_facts: no
|
||||||
remote_user: ec2-user
|
remote_user: ec2-user
|
||||||
sudo: true
|
become: true
|
||||||
roles:
|
roles:
|
||||||
- { role: ec2_elb_instance_setup, tags: test_ec2_elb }
|
- { role: ec2_elb_instance_setup, tags: test_ec2_elb }
|
||||||
|
|
||||||
|
|
|
@ -214,8 +214,8 @@
|
||||||
|
|
||||||
- name: overwrite the file as user nobody
|
- name: overwrite the file as user nobody
|
||||||
copy: dest=/tmp/worldwritable/file.txt content="baz"
|
copy: dest=/tmp/worldwritable/file.txt content="baz"
|
||||||
sudo: yes
|
become: yes
|
||||||
sudo_user: nobody
|
become_user: nobody
|
||||||
register: copy_result7
|
register: copy_result7
|
||||||
|
|
||||||
- name: assert the file was overwritten
|
- name: assert the file was overwritten
|
||||||
|
|
|
@ -92,8 +92,8 @@
|
||||||
- name: "shutdown the apache service on the first instance ({{ec2_provision_result.instances[0].public_ip}})"
|
- name: "shutdown the apache service on the first instance ({{ec2_provision_result.instances[0].public_ip}})"
|
||||||
service: name=httpd state=stopped
|
service: name=httpd state=stopped
|
||||||
remote_user: "ec2-user"
|
remote_user: "ec2-user"
|
||||||
sudo: yes
|
become: yes
|
||||||
sudo_user: root
|
become_user: root
|
||||||
delegate_to: "{{ec2_provision_result.instances[0].public_ip}}"
|
delegate_to: "{{ec2_provision_result.instances[0].public_ip}}"
|
||||||
|
|
||||||
- name: assert that the httpd service was stopped
|
- name: assert that the httpd service was stopped
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
|
|
||||||
- debug: var=fetched
|
- debug: var=fetched
|
||||||
|
|
||||||
# TODO: check the sudo and non-sudo forms of fetch because in one form we'll do
|
# TODO: check the become and non-become forms of fetch because in one form we'll do
|
||||||
# the get method of the connection plugin and in the sudo case we'll use the
|
# the get method of the connection plugin and in the become case we'll use the
|
||||||
# fetch module.
|
# fetch module.
|
||||||
|
|
||||||
- name: diff what we fetched with the original file
|
- name: diff what we fetched with the original file
|
||||||
|
@ -82,8 +82,8 @@
|
||||||
|
|
||||||
- debug: var=fetched
|
- debug: var=fetched
|
||||||
|
|
||||||
# TODO: check the sudo and non-sudo forms of fetch because in one form we'll do
|
# TODO: check the become and non-become forms of fetch because in one form we'll do
|
||||||
# the get method of the connection plugin and in the sudo case we'll use the
|
# the get method of the connection plugin and in the become case we'll use the
|
||||||
# fetch module.
|
# fetch module.
|
||||||
|
|
||||||
- name: diff what we fetched with the original file
|
- name: diff what we fetched with the original file
|
||||||
|
|
|
@ -70,8 +70,8 @@
|
||||||
|
|
||||||
- name: Ask to create a file without enough perms to change ownership
|
- name: Ask to create a file without enough perms to change ownership
|
||||||
file: path=/tmp/worldwritable/baz.txt state=touch owner=root
|
file: path=/tmp/worldwritable/baz.txt state=touch owner=root
|
||||||
sudo: yes
|
become: yes
|
||||||
sudo_user: nobody
|
become_user: nobody
|
||||||
register: chown_result
|
register: chown_result
|
||||||
ignore_errors: True
|
ignore_errors: True
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
# Create and destroy db
|
# Create and destroy db
|
||||||
#
|
#
|
||||||
- name: Create DB
|
- name: Create DB
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
state: present
|
state: present
|
||||||
name: "{{ db_name }}"
|
name: "{{ db_name }}"
|
||||||
|
@ -16,8 +16,8 @@
|
||||||
- "result.db =='{{ db_name }}'"
|
- "result.db =='{{ db_name }}'"
|
||||||
|
|
||||||
- name: Check that database created
|
- name: Check that database created
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select datname from pg_database where datname = '{{ db_name }}';" | psql
|
shell: echo "select datname from pg_database where datname = '{{ db_name }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@
|
||||||
- "result.stdout_lines[-1] == '(1 row)'"
|
- "result.stdout_lines[-1] == '(1 row)'"
|
||||||
|
|
||||||
- name: Run create on an already created db
|
- name: Run create on an already created db
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
state: present
|
state: present
|
||||||
name: "{{ db_name }}"
|
name: "{{ db_name }}"
|
||||||
|
@ -39,8 +39,8 @@
|
||||||
- "result.changed == false"
|
- "result.changed == false"
|
||||||
|
|
||||||
- name: Destroy DB
|
- name: Destroy DB
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
state: absent
|
state: absent
|
||||||
name: "{{ db_name }}"
|
name: "{{ db_name }}"
|
||||||
|
@ -52,8 +52,8 @@
|
||||||
- "result.changed == true"
|
- "result.changed == true"
|
||||||
|
|
||||||
- name: Check that database was destroyed
|
- name: Check that database was destroyed
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select datname from pg_database where datname = '{{ db_name }}';" | psql
|
shell: echo "select datname from pg_database where datname = '{{ db_name }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -62,8 +62,8 @@
|
||||||
- "result.stdout_lines[-1] == '(0 rows)'"
|
- "result.stdout_lines[-1] == '(0 rows)'"
|
||||||
|
|
||||||
- name: Destroy DB
|
- name: Destroy DB
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
state: absent
|
state: absent
|
||||||
name: "{{ db_name }}"
|
name: "{{ db_name }}"
|
||||||
|
@ -100,8 +100,8 @@
|
||||||
# Test encoding, collate, ctype, template options
|
# Test encoding, collate, ctype, template options
|
||||||
#
|
#
|
||||||
- name: Create a DB with encoding, collate, ctype, and template options
|
- name: Create a DB with encoding, collate, ctype, and template options
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
name: '{{ db_name }}'
|
name: '{{ db_name }}'
|
||||||
state: 'present'
|
state: 'present'
|
||||||
|
@ -111,8 +111,8 @@
|
||||||
template: 'template0'
|
template: 'template0'
|
||||||
|
|
||||||
- name: Check that the DB has all of our options
|
- name: Check that the DB has all of our options
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select datname, pg_encoding_to_char(encoding), datcollate, datctype from pg_database where datname = '{{ db_name }}';" | psql
|
shell: echo "select datname, pg_encoding_to_char(encoding), datcollate, datctype from pg_database where datname = '{{ db_name }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -126,8 +126,8 @@
|
||||||
- "'en_US' not in result.stdout_lines[-2]"
|
- "'en_US' not in result.stdout_lines[-2]"
|
||||||
|
|
||||||
- name: Check that running db cration with options a second time does nothing
|
- name: Check that running db cration with options a second time does nothing
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
name: '{{ db_name }}'
|
name: '{{ db_name }}'
|
||||||
state: 'present'
|
state: 'present'
|
||||||
|
@ -143,8 +143,8 @@
|
||||||
|
|
||||||
|
|
||||||
- name: Check that attempting to change encoding returns an error
|
- name: Check that attempting to change encoding returns an error
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
name: '{{ db_name }}'
|
name: '{{ db_name }}'
|
||||||
state: 'present'
|
state: 'present'
|
||||||
|
@ -160,15 +160,15 @@
|
||||||
- 'result.failed == True'
|
- 'result.failed == True'
|
||||||
|
|
||||||
- name: Cleanup test DB
|
- name: Cleanup test DB
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
name: '{{ db_name }}'
|
name: '{{ db_name }}'
|
||||||
state: 'absent'
|
state: 'absent'
|
||||||
|
|
||||||
- shell: echo "select datname, pg_encoding_to_char(encoding), datcollate, datctype from pg_database where datname = '{{ db_name }}';" | psql
|
- shell: echo "select datname, pg_encoding_to_char(encoding), datcollate, datctype from pg_database where datname = '{{ db_name }}';" | psql
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
|
@ -179,8 +179,8 @@
|
||||||
# Create and destroy user
|
# Create and destroy user
|
||||||
#
|
#
|
||||||
- name: Create a user
|
- name: Create a user
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
encrypted: 'yes'
|
encrypted: 'yes'
|
||||||
|
@ -193,8 +193,8 @@
|
||||||
- "result.changed == True"
|
- "result.changed == True"
|
||||||
|
|
||||||
- name: Check that they were created
|
- name: Check that they were created
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select * from pg_user where usename='{{ db_user1 }}';" | psql
|
shell: echo "select * from pg_user where usename='{{ db_user1 }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -203,8 +203,8 @@
|
||||||
- "result.stdout_lines[-1] == '(1 row)'"
|
- "result.stdout_lines[-1] == '(1 row)'"
|
||||||
|
|
||||||
- name: Check that creating user a second time does nothing
|
- name: Check that creating user a second time does nothing
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
encrypted: 'yes'
|
encrypted: 'yes'
|
||||||
|
@ -217,8 +217,8 @@
|
||||||
- "result.changed == False"
|
- "result.changed == False"
|
||||||
|
|
||||||
- name: Remove user
|
- name: Remove user
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
state: 'absent'
|
state: 'absent'
|
||||||
|
@ -230,8 +230,8 @@
|
||||||
- "result.changed == True"
|
- "result.changed == True"
|
||||||
|
|
||||||
- name: Check that they were removed
|
- name: Check that they were removed
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select * from pg_user where usename='{{ db_user1 }}';" | psql
|
shell: echo "select * from pg_user where usename='{{ db_user1 }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -240,8 +240,8 @@
|
||||||
- "result.stdout_lines[-1] == '(0 rows)'"
|
- "result.stdout_lines[-1] == '(0 rows)'"
|
||||||
|
|
||||||
- name: Check that removing user a second time does nothing
|
- name: Check that removing user a second time does nothing
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
state: 'absent'
|
state: 'absent'
|
||||||
|
@ -253,16 +253,16 @@
|
||||||
- "result.changed == False"
|
- "result.changed == False"
|
||||||
|
|
||||||
- name: Create a user with all role attributes
|
- name: Create a user with all role attributes
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
state: "present"
|
state: "present"
|
||||||
role_attr_flags: "SUPERUSER,CREATEROLE,CREATEDB,INHERIT,login"
|
role_attr_flags: "SUPERUSER,CREATEROLE,CREATEDB,INHERIT,login"
|
||||||
|
|
||||||
- name: Check that the user has the requested role attributes
|
- name: Check that the user has the requested role attributes
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select 'super:'||rolsuper, 'createrole:'||rolcreaterole, 'create:'||rolcreatedb, 'inherit:'||rolinherit, 'login:'||rolcanlogin from pg_roles where rolname='{{ db_user1 }}';" | psql
|
shell: echo "select 'super:'||rolsuper, 'createrole:'||rolcreaterole, 'create:'||rolcreatedb, 'inherit:'||rolinherit, 'login:'||rolcanlogin from pg_roles where rolname='{{ db_user1 }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -276,8 +276,8 @@
|
||||||
- "'login:t' in result.stdout_lines[-2]"
|
- "'login:t' in result.stdout_lines[-2]"
|
||||||
|
|
||||||
- name: Modify a user to have no role attributes
|
- name: Modify a user to have no role attributes
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
state: "present"
|
state: "present"
|
||||||
|
@ -290,8 +290,8 @@
|
||||||
- "result.changed == True"
|
- "result.changed == True"
|
||||||
|
|
||||||
- name: Check that the user has the requested role attributes
|
- name: Check that the user has the requested role attributes
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select 'super:'||rolsuper, 'createrole:'||rolcreaterole, 'create:'||rolcreatedb, 'inherit:'||rolinherit, 'login:'||rolcanlogin from pg_roles where rolname='{{ db_user1 }}';" | psql
|
shell: echo "select 'super:'||rolsuper, 'createrole:'||rolcreaterole, 'create:'||rolcreatedb, 'inherit:'||rolinherit, 'login:'||rolcanlogin from pg_roles where rolname='{{ db_user1 }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -305,8 +305,8 @@
|
||||||
- "'login:f' in result.stdout_lines[-2]"
|
- "'login:f' in result.stdout_lines[-2]"
|
||||||
|
|
||||||
- name: Modify a single role attribute on a user
|
- name: Modify a single role attribute on a user
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
state: "present"
|
state: "present"
|
||||||
|
@ -319,8 +319,8 @@
|
||||||
- "result.changed == True"
|
- "result.changed == True"
|
||||||
|
|
||||||
- name: Check that the user has the requested role attributes
|
- name: Check that the user has the requested role attributes
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select 'super:'||rolsuper, 'createrole:'||rolcreaterole, 'create:'||rolcreatedb, 'inherit:'||rolinherit, 'login:'||rolcanlogin from pg_roles where rolname='{{ db_user1 }}';" | psql
|
shell: echo "select 'super:'||rolsuper, 'createrole:'||rolcreaterole, 'create:'||rolcreatedb, 'inherit:'||rolinherit, 'login:'||rolcanlogin from pg_roles where rolname='{{ db_user1 }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -334,15 +334,15 @@
|
||||||
- "'login:t' in result.stdout_lines[-2]"
|
- "'login:t' in result.stdout_lines[-2]"
|
||||||
|
|
||||||
- name: Cleanup the user
|
- name: Cleanup the user
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
state: 'absent'
|
state: 'absent'
|
||||||
|
|
||||||
- name: Check that they were removed
|
- name: Check that they were removed
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select * from pg_user where usename='{{ db_user1 }}';" | psql
|
shell: echo "select * from pg_user where usename='{{ db_user1 }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -356,24 +356,24 @@
|
||||||
# Test db ownership
|
# Test db ownership
|
||||||
#
|
#
|
||||||
- name: Create an unprivileged user to own a DB
|
- name: Create an unprivileged user to own a DB
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
encrypted: 'yes'
|
encrypted: 'yes'
|
||||||
password: "md55c8ccfd9d6711fc69a7eae647fc54f51"
|
password: "md55c8ccfd9d6711fc69a7eae647fc54f51"
|
||||||
|
|
||||||
- name: Create db with user ownership
|
- name: Create db with user ownership
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
name: "{{ db_name }}"
|
name: "{{ db_name }}"
|
||||||
state: "present"
|
state: "present"
|
||||||
owner: "{{ db_user1 }}"
|
owner: "{{ db_user1 }}"
|
||||||
|
|
||||||
- name: Check that the user owns the newly created DB
|
- name: Check that the user owns the newly created DB
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select pg_catalog.pg_get_userbyid(datdba) from pg_catalog.pg_database where datname = '{{ db_name }}';" | psql
|
shell: echo "select pg_catalog.pg_get_userbyid(datdba) from pg_catalog.pg_database where datname = '{{ db_name }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -383,8 +383,8 @@
|
||||||
- "'{{ db_user1 }}' == '{{ result.stdout_lines[-2] | trim }}'"
|
- "'{{ db_user1 }}' == '{{ result.stdout_lines[-2] | trim }}'"
|
||||||
|
|
||||||
- name: Change the owner on an existing db
|
- name: Change the owner on an existing db
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
name: "{{ db_name }}"
|
name: "{{ db_name }}"
|
||||||
state: "present"
|
state: "present"
|
||||||
|
@ -397,8 +397,8 @@
|
||||||
- "result.changed == True"
|
- "result.changed == True"
|
||||||
|
|
||||||
- name: Check that the user owns the newly created DB
|
- name: Check that the user owns the newly created DB
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select pg_catalog.pg_get_userbyid(datdba) from pg_catalog.pg_database where datname = '{{ db_name }}';" | psql
|
shell: echo "select pg_catalog.pg_get_userbyid(datdba) from pg_catalog.pg_database where datname = '{{ db_name }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -408,15 +408,15 @@
|
||||||
- "'postgres' == '{{ result.stdout_lines[-2] | trim }}'"
|
- "'postgres' == '{{ result.stdout_lines[-2] | trim }}'"
|
||||||
|
|
||||||
- name: Cleanup db
|
- name: Cleanup db
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
name: "{{ db_name }}"
|
name: "{{ db_name }}"
|
||||||
state: "absent"
|
state: "absent"
|
||||||
|
|
||||||
- name: Check that database was destroyed
|
- name: Check that database was destroyed
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select datname from pg_database where datname = '{{ db_name }}';" | psql
|
shell: echo "select datname from pg_database where datname = '{{ db_name }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -425,15 +425,15 @@
|
||||||
- "result.stdout_lines[-1] == '(0 rows)'"
|
- "result.stdout_lines[-1] == '(0 rows)'"
|
||||||
|
|
||||||
- name: Cleanup test user
|
- name: Cleanup test user
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
state: 'absent'
|
state: 'absent'
|
||||||
|
|
||||||
- name: Check that they were removed
|
- name: Check that they were removed
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select * from pg_user where usename='{{ db_user1 }}';" | psql
|
shell: echo "select * from pg_user where usename='{{ db_user1 }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -445,24 +445,24 @@
|
||||||
# Test settings privleges
|
# Test settings privleges
|
||||||
#
|
#
|
||||||
- name: Create db
|
- name: Create db
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
name: "{{ db_name }}"
|
name: "{{ db_name }}"
|
||||||
state: "present"
|
state: "present"
|
||||||
|
|
||||||
- name: Create some tables on the db
|
- name: Create some tables on the db
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "create table test_table1 (field text);" | psql {{ db_name }}
|
shell: echo "create table test_table1 (field text);" | psql {{ db_name }}
|
||||||
|
|
||||||
- sudo_user: postgres
|
- become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "create table test_table2 (field text);" | psql {{ db_name }}
|
shell: echo "create table test_table2 (field text);" | psql {{ db_name }}
|
||||||
|
|
||||||
- name: Create a user with some permissions on the db
|
- name: Create a user with some permissions on the db
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
encrypted: 'yes'
|
encrypted: 'yes'
|
||||||
|
@ -471,20 +471,20 @@
|
||||||
priv: 'test_table1:INSERT,SELECT,UPDATE,DELETE,TRUNCATE,REFERENCES,TRIGGER/test_table2:INSERT/CREATE,CONNECT,TEMP'
|
priv: 'test_table1:INSERT,SELECT,UPDATE,DELETE,TRUNCATE,REFERENCES,TRIGGER/test_table2:INSERT/CREATE,CONNECT,TEMP'
|
||||||
|
|
||||||
- name: Check that the user has the requested permissions (table1)
|
- name: Check that the user has the requested permissions (table1)
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table1';" | psql {{ db_name }}
|
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table1';" | psql {{ db_name }}
|
||||||
register: result_table1
|
register: result_table1
|
||||||
|
|
||||||
- name: Check that the user has the requested permissions (table2)
|
- name: Check that the user has the requested permissions (table2)
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table2';" | psql {{ db_name }}
|
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table2';" | psql {{ db_name }}
|
||||||
register: result_table2
|
register: result_table2
|
||||||
|
|
||||||
- name: Check that the user has the requested permissions (database)
|
- name: Check that the user has the requested permissions (database)
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select datacl from pg_database where datname='{{ db_name }}';" | psql {{ db_name }}
|
shell: echo "select datacl from pg_database where datname='{{ db_name }}';" | psql {{ db_name }}
|
||||||
register: result_database
|
register: result_database
|
||||||
|
|
||||||
|
@ -504,8 +504,8 @@
|
||||||
- "'{{ db_user1 }}=CTc/postgres' in result_database.stdout_lines[-2]"
|
- "'{{ db_user1 }}=CTc/postgres' in result_database.stdout_lines[-2]"
|
||||||
|
|
||||||
- name: Add another permission for the user
|
- name: Add another permission for the user
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
encrypted: 'yes'
|
encrypted: 'yes'
|
||||||
|
@ -520,8 +520,8 @@
|
||||||
- "results.changed == True"
|
- "results.changed == True"
|
||||||
|
|
||||||
- name: Check that the user has the requested permissions (table2)
|
- name: Check that the user has the requested permissions (table2)
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table2';" | psql {{ db_name }}
|
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table2';" | psql {{ db_name }}
|
||||||
register: result_table2
|
register: result_table2
|
||||||
|
|
||||||
|
@ -538,8 +538,8 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
- name: Revoke a privilege
|
- name: Revoke a privilege
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_privs:
|
postgresql_privs:
|
||||||
type: "table"
|
type: "table"
|
||||||
state: "absent"
|
state: "absent"
|
||||||
|
@ -555,8 +555,8 @@
|
||||||
- "results.changed == True"
|
- "results.changed == True"
|
||||||
|
|
||||||
- name: Check that the user has the requested permissions (table2)
|
- name: Check that the user has the requested permissions (table2)
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table2';" | psql {{ db_name }}
|
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table2';" | psql {{ db_name }}
|
||||||
register: result_table2
|
register: result_table2
|
||||||
|
|
||||||
|
@ -566,8 +566,8 @@
|
||||||
- "'SELECT' == '{{ result_table2.stdout_lines[-2] | trim }}'"
|
- "'SELECT' == '{{ result_table2.stdout_lines[-2] | trim }}'"
|
||||||
|
|
||||||
- name: Revoke many privileges on multiple tables
|
- name: Revoke many privileges on multiple tables
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_privs:
|
postgresql_privs:
|
||||||
state: "absent"
|
state: "absent"
|
||||||
roles: "{{ db_user1 }}"
|
roles: "{{ db_user1 }}"
|
||||||
|
@ -582,14 +582,14 @@
|
||||||
- "results.changed == True"
|
- "results.changed == True"
|
||||||
|
|
||||||
- name: Check that permissions were revoked (table1)
|
- name: Check that permissions were revoked (table1)
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table1';" | psql {{ db_name }}
|
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table1';" | psql {{ db_name }}
|
||||||
register: result_table1
|
register: result_table1
|
||||||
|
|
||||||
- name: Check that permissions were revoked (table2)
|
- name: Check that permissions were revoked (table2)
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table2';" | psql {{ db_name }}
|
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table2';" | psql {{ db_name }}
|
||||||
register: result_table2
|
register: result_table2
|
||||||
|
|
||||||
|
@ -599,8 +599,8 @@
|
||||||
- "result_table2.stdout_lines[-1] == '(0 rows)'"
|
- "result_table2.stdout_lines[-1] == '(0 rows)'"
|
||||||
|
|
||||||
- name: Revoke database privileges
|
- name: Revoke database privileges
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_privs:
|
postgresql_privs:
|
||||||
type: "database"
|
type: "database"
|
||||||
state: "absent"
|
state: "absent"
|
||||||
|
@ -610,8 +610,8 @@
|
||||||
db: "{{ db_name }}"
|
db: "{{ db_name }}"
|
||||||
|
|
||||||
- name: Check that the user has the requested permissions (database)
|
- name: Check that the user has the requested permissions (database)
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select datacl from pg_database where datname='{{ db_name }}';" | psql {{ db_name }}
|
shell: echo "select datacl from pg_database where datname='{{ db_name }}';" | psql {{ db_name }}
|
||||||
register: result_database
|
register: result_database
|
||||||
|
|
||||||
|
@ -621,8 +621,8 @@
|
||||||
- "'{{ db_user1 }}' not in result_database.stdout"
|
- "'{{ db_user1 }}' not in result_database.stdout"
|
||||||
|
|
||||||
- name: Grant database privileges
|
- name: Grant database privileges
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_privs:
|
postgresql_privs:
|
||||||
type: "database"
|
type: "database"
|
||||||
state: "present"
|
state: "present"
|
||||||
|
@ -638,8 +638,8 @@
|
||||||
- "results.changed == True"
|
- "results.changed == True"
|
||||||
|
|
||||||
- name: Check that the user has the requested permissions (database)
|
- name: Check that the user has the requested permissions (database)
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select datacl from pg_database where datname='{{ db_name }}';" | psql {{ db_name }}
|
shell: echo "select datacl from pg_database where datname='{{ db_name }}';" | psql {{ db_name }}
|
||||||
register: result_database
|
register: result_database
|
||||||
|
|
||||||
|
@ -649,8 +649,8 @@
|
||||||
- "'{{ db_user1 }}=Cc' in result_database.stdout"
|
- "'{{ db_user1 }}=Cc' in result_database.stdout"
|
||||||
|
|
||||||
- name: Grant a single privilege on a table
|
- name: Grant a single privilege on a table
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_privs:
|
postgresql_privs:
|
||||||
state: "present"
|
state: "present"
|
||||||
roles: "{{ db_user1 }}"
|
roles: "{{ db_user1 }}"
|
||||||
|
@ -659,8 +659,8 @@
|
||||||
db: "{{ db_name }}"
|
db: "{{ db_name }}"
|
||||||
|
|
||||||
- name: Check that permissions were added (table1)
|
- name: Check that permissions were added (table1)
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table1';" | psql {{ db_name }}
|
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table1';" | psql {{ db_name }}
|
||||||
register: result_table1
|
register: result_table1
|
||||||
|
|
||||||
|
@ -670,8 +670,8 @@
|
||||||
- "'{{ result_table1.stdout_lines[-2] | trim }}' == 'INSERT'"
|
- "'{{ result_table1.stdout_lines[-2] | trim }}' == 'INSERT'"
|
||||||
|
|
||||||
- name: Grant many privileges on multiple tables
|
- name: Grant many privileges on multiple tables
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_privs:
|
postgresql_privs:
|
||||||
state: "present"
|
state: "present"
|
||||||
roles: "{{ db_user1 }}"
|
roles: "{{ db_user1 }}"
|
||||||
|
@ -680,14 +680,14 @@
|
||||||
db: "{{ db_name }}"
|
db: "{{ db_name }}"
|
||||||
|
|
||||||
- name: Check that permissions were added (table1)
|
- name: Check that permissions were added (table1)
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table1';" | psql {{ db_name }}
|
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table1';" | psql {{ db_name }}
|
||||||
register: result_table1
|
register: result_table1
|
||||||
|
|
||||||
- name: Check that permissions were added (table2)
|
- name: Check that permissions were added (table2)
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table2';" | psql {{ db_name }}
|
shell: echo "select privilege_type from information_schema.role_table_grants where grantee='{{ db_user1 }}' and table_name='test_table2';" | psql {{ db_name }}
|
||||||
register: result_table2
|
register: result_table2
|
||||||
|
|
||||||
|
@ -714,15 +714,15 @@
|
||||||
# Cleanup
|
# Cleanup
|
||||||
#
|
#
|
||||||
- name: Cleanup db
|
- name: Cleanup db
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
name: "{{ db_name }}"
|
name: "{{ db_name }}"
|
||||||
state: "absent"
|
state: "absent"
|
||||||
|
|
||||||
- name: Check that database was destroyed
|
- name: Check that database was destroyed
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select datname from pg_database where datname = '{{ db_name }}';" | psql
|
shell: echo "select datname from pg_database where datname = '{{ db_name }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -731,15 +731,15 @@
|
||||||
- "result.stdout_lines[-1] == '(0 rows)'"
|
- "result.stdout_lines[-1] == '(0 rows)'"
|
||||||
|
|
||||||
- name: Cleanup test user
|
- name: Cleanup test user
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
state: 'absent'
|
state: 'absent'
|
||||||
|
|
||||||
- name: Check that they were removed
|
- name: Check that they were removed
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
sudo: True
|
become: True
|
||||||
shell: echo "select * from pg_user where usename='{{ db_user1 }}';" | psql
|
shell: echo "select * from pg_user where usename='{{ db_user1 }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -751,8 +751,8 @@
|
||||||
# Test login_user functionality
|
# Test login_user functionality
|
||||||
#
|
#
|
||||||
- name: Create a user to test login module parameters
|
- name: Create a user to test login module parameters
|
||||||
sudo: True
|
become: True
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
state: "present"
|
state: "present"
|
||||||
|
@ -769,8 +769,8 @@
|
||||||
login_host: "localhost"
|
login_host: "localhost"
|
||||||
|
|
||||||
- name: Check that database created
|
- name: Check that database created
|
||||||
sudo: True
|
become: True
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
shell: echo "select datname from pg_database where datname = '{{ db_name }}';" | psql
|
shell: echo "select datname from pg_database where datname = '{{ db_name }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -790,8 +790,8 @@
|
||||||
login_host: "localhost"
|
login_host: "localhost"
|
||||||
|
|
||||||
- name: Check that they were created
|
- name: Check that they were created
|
||||||
sudo: True
|
become: True
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
shell: echo "select * from pg_user where usename='{{ db_user2 }}';" | psql
|
shell: echo "select * from pg_user where usename='{{ db_user2 }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -812,8 +812,8 @@
|
||||||
host: "localhost"
|
host: "localhost"
|
||||||
|
|
||||||
- name: Check that the user has the requested permissions (database)
|
- name: Check that the user has the requested permissions (database)
|
||||||
sudo: True
|
become: True
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
shell: echo "select datacl from pg_database where datname='{{ db_name }}';" | psql {{ db_name }}
|
shell: echo "select datacl from pg_database where datname='{{ db_name }}';" | psql {{ db_name }}
|
||||||
register: result_database
|
register: result_database
|
||||||
|
|
||||||
|
@ -833,8 +833,8 @@
|
||||||
login_host: "localhost"
|
login_host: "localhost"
|
||||||
|
|
||||||
- name: Check that they were removed
|
- name: Check that they were removed
|
||||||
sudo: True
|
become: True
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
shell: echo "select * from pg_user where usename='{{ db_user2 }}';" | psql
|
shell: echo "select * from pg_user where usename='{{ db_user2 }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -851,8 +851,8 @@
|
||||||
login_host: "localhost"
|
login_host: "localhost"
|
||||||
|
|
||||||
- name: Check that database was destroyed
|
- name: Check that database was destroyed
|
||||||
sudo: True
|
become: True
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
shell: echo "select datname from pg_database where datname = '{{ db_name }}';" | psql
|
shell: echo "select datname from pg_database where datname = '{{ db_name }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
@ -864,15 +864,15 @@
|
||||||
# Cleanup
|
# Cleanup
|
||||||
#
|
#
|
||||||
- name: Cleanup test user
|
- name: Cleanup test user
|
||||||
sudo: True
|
become: True
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
name: "{{ db_user1 }}"
|
name: "{{ db_user1 }}"
|
||||||
state: 'absent'
|
state: 'absent'
|
||||||
|
|
||||||
- name: Check that they were removed
|
- name: Check that they were removed
|
||||||
sudo: True
|
become: True
|
||||||
sudo_user: postgres
|
become_user: postgres
|
||||||
shell: echo "select * from pg_user where usename='{{ db_user1 }}';" | psql
|
shell: echo "select * from pg_user where usename='{{ db_user1 }}';" | psql
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
|
|
|
@ -242,8 +242,8 @@
|
||||||
|
|
||||||
#- name: overwrite the file as user nobody
|
#- name: overwrite the file as user nobody
|
||||||
# win_copy: dest=/tmp/worldwritable/file.txt content="baz"
|
# win_copy: dest=/tmp/worldwritable/file.txt content="baz"
|
||||||
# sudo: yes
|
# become: yes
|
||||||
# sudo_user: nobody
|
# become_user: nobody
|
||||||
# register: copy_result7
|
# register: copy_result7
|
||||||
|
|
||||||
#- name: assert the file was overwritten
|
#- name: assert the file was overwritten
|
||||||
|
|
|
@ -70,8 +70,8 @@
|
||||||
|
|
||||||
#- name: Ask to create a file without enough perms to change ownership
|
#- name: Ask to create a file without enough perms to change ownership
|
||||||
# win_file: path=/tmp/worldwritable/baz.txt state=touch owner=root
|
# win_file: path=/tmp/worldwritable/baz.txt state=touch owner=root
|
||||||
# sudo: yes
|
# become: yes
|
||||||
# sudo_user: nobody
|
# become_user: nobody
|
||||||
# register: chown_result
|
# register: chown_result
|
||||||
# ignore_errors: True
|
# ignore_errors: True
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,8 @@ class TestPlay(unittest.TestCase):
|
||||||
gather_facts=False,
|
gather_facts=False,
|
||||||
connection='local',
|
connection='local',
|
||||||
remote_user="root",
|
remote_user="root",
|
||||||
sudo=True,
|
become=True,
|
||||||
sudo_user="testing",
|
become_user="testing",
|
||||||
))
|
))
|
||||||
|
|
||||||
def test_play_with_user_conflict(self):
|
def test_play_with_user_conflict(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue