k8s_auth: use group module defaults in example (#52712)

The yaml anchor thing was just a stopgap until all the module defaults
group stuff got merged. Which it did.
This commit is contained in:
Mariusz Mazur 2019-03-04 18:55:30 +01:00 committed by ansibot
commit 4ea51fd7ee

View file

@ -74,42 +74,37 @@ requirements:
''' '''
EXAMPLES = ''' EXAMPLES = '''
- block: - hosts: localhost
# It's good practice to store login credentials in a secure vault and not module_defaults:
# directly in playbooks. group/k8s:
- include_vars: k8s_passwords.yml
- name: Log in (obtain access token)
k8s_auth:
host: https://k8s.example.com/ host: https://k8s.example.com/
ssl_ca_cert: ca.pem ssl_ca_cert: ca.pem
username: admin tasks:
password: "{{ k8s_admin_password }}" - block:
register: k8s_auth_results # It's good practice to store login credentials in a secure vault and not
# directly in playbooks.
- include_vars: k8s_passwords.yml
- name: Preserve auth info as both a fact and a yaml anchor for easy access later - name: Log in (obtain access token)
# Both the fact and the anchor are called 'k8s_auth_params' k8s_auth:
set_fact: username: admin
k8s_auth_params: &k8s_auth_params password: "{{ k8s_admin_password }}"
host: "{{ k8s_auth_results.k8s_auth.host }}" register: k8s_auth_results
ssl_ca_cert: "{{ k8s_auth_results.k8s_auth.ssl_ca_cert }}"
verify_ssl: "{{ k8s_auth_results.k8s_auth.verify_ssl }}" # Previous task provides the token/api_key, while all other parameters
# are taken from module_defaults
- name: Get a list of all pods from any namespace
k8s_facts:
api_key: "{{ k8s_auth_results.k8s_auth.api_key }}" api_key: "{{ k8s_auth_results.k8s_auth.api_key }}"
kind: Pod
register: pod_list
# Previous task generated I(k8s_auth) fact, which you can then use always:
# in k8s modules like this: - name: If login succeeded, try to log out (revoke access token)
- name: Get a list of all pods from any namespace when: k8s_auth_results.k8s_auth.api_key is defined
k8s_facts: k8s_auth:
<<: *k8s_auth_params state: absent
kind: Pod api_key: "{{ k8s_auth_results.k8s_auth.api_key }}"
register: pod_list
always:
- name: If login succeeded, try to log out (revoke access token)
when: k8s_auth_params is defined
k8s_auth:
state: absent
<<: *k8s_auth_params
''' '''
# Returned value names need to match k8s modules parameter names, to make it # Returned value names need to match k8s modules parameter names, to make it