Issue #3: Update examples in README and add note about OpenShift Python library.

This commit is contained in:
Jeff Geerling
2020-02-03 12:41:42 -06:00
parent 29765e5e56
commit 8060f6123f

View File

@@ -40,9 +40,15 @@ You can also include it in a `requirements.yml` file and install it via `ansible
--- ---
collections: collections:
- name: community.kubernetes - name: community.kubernetes
version: 1.0.0 version: 0.9.0
``` ```
### Installing the OpenShift Python Library
Content in this collection requires the [OpenShift Python client](https://pypi.org/project/openshift/) to interact with Kubernetes' APIs. You can install it with:
pip3 install openshift
### Using modules from the Kubernetes Collection in your playbooks ### Using modules from the Kubernetes Collection in your playbooks
You can either call modules by their Fully Qualified Collection Namespace (FQCN), like `community.kubernetes.k8s_info`, or you can call modules by their short name if you list the `community.kubernetes` collection in the playbook's `collections`, like so: You can either call modules by their Fully Qualified Collection Namespace (FQCN), like `community.kubernetes.k8s_info`, or you can call modules by their short name if you list the `community.kubernetes` collection in the playbook's `collections`, like so:
@@ -57,15 +63,39 @@ You can either call modules by their Fully Qualified Collection Namespace (FQCN)
- community.kubernetes - community.kubernetes
tasks: tasks:
- name: Get a list of all pods in the kube-system namespace. - name: Ensure the myapp Namespace exists.
k8s_info: k8s:
kind: Pod api_version: v1
namespace: kube-system kind: Namespace
register: system_pods name: myapp
state: present
- name: Display pod information for pods in kube-system namespace. - name: Ensure the myapp Service exists in the myapp Namespace.
k8s:
state: present
definition:
apiVersion: v1
kind: Service
metadata:
name: myapp
namespace: myapp
spec:
type: LoadBalancer
ports:
- port: 8080
targetPort: 8080
selector:
app: myapp
- name: Get a list of all Services in the myapp namespace.
k8s_info:
kind: Service
namespace: myapp
register: myapp_services
- name: Display number of Services in the myapp namespace.
debug: debug:
var: system_pods.resources | count var: myapp_services.resources | count
``` ```