Docs: true/false with boolean values (#78980)

* Adding FQCN community.postgresql. to postgresql modules
pull/79019/head^2
prayatharth 3 years ago committed by GitHub
parent 6d0aeac1e1
commit 56285b1d2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -27,7 +27,7 @@ Let's say we want to test the ``postgresql_user`` module invoked with the ``name
.. code-block:: yaml .. code-block:: yaml
- name: Create PostgreSQL user and store module's output to the result variable - name: Create PostgreSQL user and store module's output to the result variable
postgresql_user: community.postgresql.postgresql_user:
name: test_user name: test_user
register: result register: result
@ -37,7 +37,7 @@ Let's say we want to test the ``postgresql_user`` module invoked with the ``name
- result is changed - result is changed
- name: Check actual system state with another module, in other words, that the user exists - name: Check actual system state with another module, in other words, that the user exists
postgresql_query: community.postgresql.postgresql_query:
query: SELECT * FROM pg_authid WHERE rolename = 'test_user' query: SELECT * FROM pg_authid WHERE rolename = 'test_user'
register: query_result register: query_result
@ -129,7 +129,7 @@ To check a task:
2. If the module changes the system state, check the actual system state using at least one other module. For example, if the module changes a file, we can check that the file has been changed by checking its checksum with the :ref:`stat <ansible_collections.ansible.builtin.stat_module>` module before and after the test tasks. 2. If the module changes the system state, check the actual system state using at least one other module. For example, if the module changes a file, we can check that the file has been changed by checking its checksum with the :ref:`stat <ansible_collections.ansible.builtin.stat_module>` module before and after the test tasks.
3. Run the same task with ``check_mode: yes`` if check-mode is supported by the module. Check with other modules that the actual system state has not been changed. 3. Run the same task with ``check_mode: yes`` if check-mode is supported by the module. Check with other modules that the actual system state has not been changed.
4. Cover cases when the module must fail. Use the ``ignore_errors: yes`` option and check the returned message with the ``assert`` module. 4. Cover cases when the module must fail. Use the ``ignore_errors: true`` option and check the returned message with the ``assert`` module.
Example: Example:
@ -139,7 +139,6 @@ Example:
abstract_module: abstract_module:
... ...
register: result register: result
ignore_errors: yes
- name: Check the task fails and its error message - name: Check the task fails and its error message
assert: assert:

@ -189,7 +189,7 @@ With all of the targets now removed, the current state is as if we do not have a
creates: /etc/postgresql/12/ creates: /etc/postgresql/12/
- name: Start PostgreSQL service - name: Start PostgreSQL service
service: ansible.builtin.service:
name: postgresql name: postgresql
state: started state: started
@ -213,9 +213,9 @@ That is enough for our very basic example.
.. code-block:: yaml .. code-block:: yaml
- name: Test postgresql_info module - name: Test postgresql_info module
become: yes become: true
become_user: postgres become_user: postgres
postgresql_info: community.postgresql.postgresql_info:
login_user: postgres login_user: postgres
login_db: postgres login_db: postgres
register: result register: result

@ -44,7 +44,7 @@ We will add the following code to the file.
# https://github.com/ansible-collections/community.postgresql/issues/NUM # https://github.com/ansible-collections/community.postgresql/issues/NUM
- name: Test user name containing underscore - name: Test user name containing underscore
postgresql_user: community.postgresql.postgresql_user:
name: underscored_user name: underscored_user
register: result register: result
@ -54,7 +54,7 @@ We will add the following code to the file.
- result is changed - result is changed
- name: Query the database if the user exists - name: Query the database if the user exists
postgresql_query: community.postgresql.postgresql_query:
query: SELECT * FROM pg_authid WHERE rolename = 'underscored_user' query: SELECT * FROM pg_authid WHERE rolename = 'underscored_user'
register: result register: result
@ -108,9 +108,8 @@ We will add the following code to the file.
# https://github.com/ansible-collections/community.postgresql/issues/NUM # https://github.com/ansible-collections/community.postgresql/issues/NUM
# We should also run the same tasks with check_mode: yes. We omit it here for simplicity. # We should also run the same tasks with check_mode: yes. We omit it here for simplicity.
- name: Test for new_option, create new user WITHOUT the attribute - name: Test for new_option, create new user WITHOUT the attribute
postgresql_user: community.postgresql.postgresql_user:
name: test_user name: test_user
add_attribute: no
register: result register: result
- name: Check the module returns what we expect - name: Check the module returns what we expect
@ -119,7 +118,7 @@ We will add the following code to the file.
- result is changed - result is changed
- name: Query the database if the user exists but does not have the attribute (it is NULL) - name: Query the database if the user exists but does not have the attribute (it is NULL)
postgresql_query: community.postgresql.postgresql_query:
query: SELECT * FROM pg_authid WHERE rolename = 'test_user' AND attribute = NULL query: SELECT * FROM pg_authid WHERE rolename = 'test_user' AND attribute = NULL
register: result register: result
@ -129,9 +128,8 @@ We will add the following code to the file.
- result.query_result.rowcount == 1 - result.query_result.rowcount == 1
- name: Test for new_option, create new user WITH the attribute - name: Test for new_option, create new user WITH the attribute
postgresql_user: community.postgresql.postgresql_user:
name: test_user name: test_user
add_attribute: yes
register: result register: result
- name: Check the module returns what we expect - name: Check the module returns what we expect
@ -140,7 +138,7 @@ We will add the following code to the file.
- result is changed - result is changed
- name: Query the database if the user has the attribute (it is TRUE) - name: Query the database if the user has the attribute (it is TRUE)
postgresql_query: community.postgresql.postgresql_query:
query: SELECT * FROM pg_authid WHERE rolename = 'test_user' AND attribute = 't' query: SELECT * FROM pg_authid WHERE rolename = 'test_user' AND attribute = 't'
register: result register: result
@ -153,16 +151,16 @@ Then we :ref:`run the tests<collection_run_integration_tests>` with ``postgresql
In reality, we would alternate the tasks above with the same tasks run with the ``check_mode: yes`` option to be sure our option works as expected in check-mode as well. See :ref:`Recommendations on coverage<collection_integration_recommendations>` for details. In reality, we would alternate the tasks above with the same tasks run with the ``check_mode: yes`` option to be sure our option works as expected in check-mode as well. See :ref:`Recommendations on coverage<collection_integration_recommendations>` for details.
If we expect a task to fail, we use the ``ignore_errors: yes`` option and check that the task actually failed and returned the message we expect: If we expect a task to fail, we use the ``ignore_errors: true`` option and check that the task actually failed and returned the message we expect:
.. code-block:: yaml .. code-block:: yaml
- name: Test for fail_when_true option - name: Test for fail_when_true option
postgresql_user: community.postgresql.postgresql_user:
name: test_user name: test_user
fail_when_true: yes fail_when_true: true
register: result register: result
ignore_errors: yes ignore_errors: true
- name: Check the module fails and returns message we expect - name: Check the module fails and returns message we expect
assert: assert:

@ -695,7 +695,7 @@ idempotent and does not report changes. For example:
path: C:\temp path: C:\temp
state: absent state: absent
register: remove_file_check register: remove_file_check
check_mode: yes check_mode: true
- name: get result of remove a file (check mode) - name: get result of remove a file (check mode)
win_command: powershell.exe "if (Test-Path -Path 'C:\temp') { 'true' } else { 'false' }" win_command: powershell.exe "if (Test-Path -Path 'C:\temp') { 'true' } else { 'false' }"

@ -134,7 +134,7 @@ Inventory plugins that support caching can use the general settings for the fact
# demo.aws_ec2.yml # demo.aws_ec2.yml
plugin: amazon.aws.aws_ec2 plugin: amazon.aws.aws_ec2
cache: yes cache: true
cache_plugin: ansible.builtin.jsonfile cache_plugin: ansible.builtin.jsonfile
cache_timeout: 7200 cache_timeout: 7200
cache_connection: /tmp/aws_inventory cache_connection: /tmp/aws_inventory

@ -188,10 +188,10 @@ Ansible loads any file called ``main.yml`` in a role sub-directory. This sample
tags: ntp tags: ntp
- name: be sure ntpd is running and enabled - name: be sure ntpd is running and enabled
service: ansible.builtin.service:
name: ntpd name: ntpd
state: started state: started
enabled: yes enabled: true
tags: ntp tags: ntp
Here is an example handlers file. Handlers are only triggered when certain tasks report changes. Handlers run at the end of each play: Here is an example handlers file. Handlers are only triggered when certain tasks report changes. Handlers run at the end of each play:
@ -201,7 +201,7 @@ Here is an example handlers file. Handlers are only triggered when certain tasks
--- ---
# file: roles/common/handlers/main.yml # file: roles/common/handlers/main.yml
- name: restart ntpd - name: restart ntpd
service: ansible.builtin.service:
name: ntpd name: ntpd
state: restarted state: restarted

Loading…
Cancel
Save