33// * operators/operator_sdk/osdk-ansible.adoc
44
55[id="osdk-ansible-managing-cr-status_{context}"]
6- = Managing Custom Resource status using the k8s_status Ansible module
6+ = Managing Custom Resource status using the operator_sdk.util Ansible collection
77
88Ansible-based Operators automatically update Custom Resource (CR)
9- link:https://kubernetes.io/docs/tasks/access -kubernetes-api /custom-resources/custom-resource-definitions/#status-subresource[`status` subresources]
9+ link:https://kubernetes.io/docs/tasks/extend -kubernetes/custom-resources/custom-resource-definitions/#status-subresource[`status` subresources]
1010with generic information about the previous Ansible run. This includes the
1111number of successful and failed tasks and relevant error messages as shown:
1212
@@ -34,10 +34,10 @@ status:
3434----
3535
3636Ansible-based Operators also allow Operator authors to supply custom status
37- values with the
38- link:https://github. com/fabianvf/ansible-k8s-status-module[`k8s_status`] Ansible
39- module. This allows the author to update the `status` from within Ansible with
40- any key-value pair as desired.
37+ values with the `k8s_status` Ansible module, which is included in the
38+ link:https://galaxy.ansible. com/operator_sdk/util[operator_sdk util collection].
39+ This allows the author to update the `status` from within Ansible with any
40+ key-value pair as desired.
4141
4242By default, Ansible-based Operators always include the generic Ansible
4343run output as shown above. If you would prefer your application did _not_ update
@@ -54,17 +54,17 @@ with a `manageStatus` field set to `false`:
5454- version: v1
5555 group: api.example.com
5656 kind: Foo
57- role: /opt/ansible/roles/ Foo
57+ role: Foo
5858 manageStatus: false
5959----
6060
61- . Then, use the `k8s_status` Ansible module to update the subresource. For
62- example, to update with key `foo` and value `bar`, `k8s_status` can be used as
63- shown:
61+ . Then, use the `operator_sdk.util. k8s_status` Ansible module to update the
62+ subresource. For example, to update with key `foo` and value `bar`,
63+ `operator_sdk.util` can be used as shown:
6464+
6565[source,yaml]
6666----
67- - k8s_status:
67+ - operator_sdk.util. k8s_status:
6868 api_version: app.example.com/v1
6969 kind: Foo
7070 name: "{{ meta.name }}"
@@ -73,34 +73,26 @@ shown:
7373 foo: bar
7474----
7575
76- .Additional resources
77-
78- - For more details about user-driven status management from Ansible-based
79- Operators, see the
80- link:https://github.com/operator-framework/operator-sdk/blob/master/doc/proposals/ansible-operator-status.md[Ansible Operator Status Proposal].
81-
82- [id="osdk-ansible-managing-cr-status-locally_{context}"]
83- == Using the k8s_status Ansible module when testing locally
84-
85- If your Operator takes advantage of the `k8s_status` Ansible module and you want
86- to test the Operator locally with the `operator-sdk run --local` command, you must
87- install the module in a location that Ansible expects. This is done with the
88- `library` configuration option for Ansible.
89-
90- For this example, assume the user is placing third-party Ansible modules in the
91- `/usr/share/ansible/library/` directory.
92-
93- .Procedure
94-
95- . To install the `k8s_status` module, set the `ansible.cfg` file to search in
96- the `/usr/share/ansible/library/` directory for installed Ansible modules:
97- +
76+ Collections can also be declared in the role's `meta/main.yml`, which is
77+ included for new scaffolded Ansible Operators.
78+ [source,yaml]
9879----
99- $ echo "library=/usr/share/ansible/library/" >> /etc/ansible/ansible.cfg
80+ collections:
81+ - operator_sdk.util
10082----
10183
102- . Add the `k8s_status.py` file to the `/usr/share/ansible/library/` directory :
84+ Declaring collections in the role meta allows you to invoke the `k8s_status` module directly :
10385+
86+ [source,yaml]
10487----
105- $ wget https://raw.githubusercontent.com/openshift/ocp-release-operator-sdk/master/library/k8s_status.py -O /usr/share/ansible/library/k8s_status.py
88+ k8s_status:
89+ <snip>
90+ status:
91+ foo: bar
10692----
93+
94+ .Additional resources
95+
96+ - For more details about user-driven status management from Ansible-based
97+ Operators, see the
98+ link:https://github.com/operator-framework/operator-sdk/blob/master/proposals/ansible-operator-status.md[Ansible-based Operator Status Proposal for Operator SDK].
0 commit comments