You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
3.6 KiB
YAML
147 lines
3.6 KiB
YAML
6 years ago
|
---
|
||
|
|
||
|
- name: "Create pod"
|
||
6 years ago
|
tags: create
|
||
6 years ago
|
hosts: localhost
|
||
6 years ago
|
vars:
|
||
|
pod_count: 10
|
||
|
loop_count: 5
|
||
6 years ago
|
gather_facts: no
|
||
|
tasks:
|
||
|
- name: Create a test pod
|
||
|
k8s:
|
||
|
state: present
|
||
|
definition:
|
||
|
apiVersion: v1
|
||
|
kind: Pod
|
||
|
metadata:
|
||
|
name: test-pod-{{item}}
|
||
|
namespace: default
|
||
|
spec:
|
||
|
containers:
|
||
|
- name: python2
|
||
|
image: python:2
|
||
|
args: [ "sleep", "100000" ]
|
||
6 years ago
|
- name: python3
|
||
|
image: python:3
|
||
|
args: [ "sleep", "100000" ]
|
||
|
loop: "{{ range(pod_count|int)|list }}"
|
||
6 years ago
|
|
||
|
- name: "Wait pod to be running"
|
||
|
debug: { msg: "pod is running" }
|
||
|
# status and availableReplicas might not be there. Using default value (d(default_value))
|
||
|
until: "pod_def.status.containerStatuses[0].ready"
|
||
|
# Waiting 100 s
|
||
|
retries: 50
|
||
|
delay: 2
|
||
|
vars:
|
||
|
pod_def: "{{lookup('k8s', kind='Pod', namespace='default', resource_name='test-pod-' ~ item)}}"
|
||
6 years ago
|
loop: "{{ range(pod_count|int)|list }}"
|
||
6 years ago
|
|
||
|
- name: "Add pod to pods group"
|
||
|
add_host:
|
||
|
name: "test-pod-{{item}}"
|
||
|
groups: [ "pods" ]
|
||
|
ansible_connection: "kubectl"
|
||
|
changed_when: no
|
||
|
tags: "always"
|
||
6 years ago
|
loop: "{{ range(pod_count|int)|list }}"
|
||
6 years ago
|
|
||
|
- name: "Test kubectl connection (default strategy)"
|
||
|
tags: default
|
||
|
hosts: pods
|
||
|
strategy: "linear"
|
||
6 years ago
|
vars:
|
||
|
pod_count: 10
|
||
|
loop_count: 5
|
||
6 years ago
|
gather_facts: no
|
||
|
tasks:
|
||
|
- name: "Simple shell with linear"
|
||
|
shell: ls /tmp
|
||
6 years ago
|
loop: "{{ range(loop_count|int)|list }}"
|
||
6 years ago
|
|
||
|
- name: "Simple file with linear"
|
||
|
file:
|
||
|
path: "/etc"
|
||
|
state: directory
|
||
6 years ago
|
loop: "{{ range(loop_count|int)|list }}"
|
||
|
|
||
|
- block:
|
||
|
- name: "Check python version on python3 container"
|
||
|
command: python --version
|
||
|
vars:
|
||
|
ansible_kubectl_container: python3
|
||
|
register: _
|
||
|
|
||
|
- assert: { that: "'Python 3' in _.stdout" }
|
||
|
|
||
|
- debug: var=_.stdout,_.stderr
|
||
|
run_once: yes
|
||
|
|
||
|
- name: "Check python version on default container"
|
||
|
command: python --version
|
||
|
register: _
|
||
|
|
||
|
- assert: { that: "'Python 2' in _.stderr" }
|
||
|
|
||
|
- debug: var=_.stdout,_.stderr
|
||
|
run_once: yes
|
||
6 years ago
|
|
||
|
- name: "Test kubectl connection (mitogen strategy)"
|
||
|
tags: mitogen
|
||
|
hosts: pods
|
||
|
strategy: "mitogen_linear"
|
||
6 years ago
|
vars:
|
||
|
pod_count: 10
|
||
|
loop_count: 5
|
||
6 years ago
|
gather_facts: no
|
||
|
tasks:
|
||
|
- name: "Simple shell with mitogen"
|
||
|
shell: ls /tmp
|
||
6 years ago
|
loop: "{{ range(loop_count|int)|list }}"
|
||
6 years ago
|
|
||
|
- name: "Simple file with mitogen"
|
||
|
file:
|
||
|
path: "/etc"
|
||
|
state: directory
|
||
6 years ago
|
loop: "{{ range(loop_count|int)|list }}"
|
||
|
|
||
|
- block:
|
||
|
- name: "Check python version on python3 container"
|
||
|
command: python --version
|
||
|
vars:
|
||
|
ansible_kubectl_container: python3
|
||
|
register: _
|
||
|
|
||
|
- assert: { that: "'Python 3' in _.stdout" }
|
||
|
|
||
|
- debug: var=_.stdout,_.stderr
|
||
|
run_once: yes
|
||
|
|
||
|
- name: "Check python version on default container"
|
||
|
command: python --version
|
||
|
register: _
|
||
|
|
||
|
- assert: { that: "'Python 2' in _.stderr" }
|
||
|
|
||
|
- debug: var=_.stdout,_.stderr
|
||
|
run_once: yes
|
||
|
tags: check
|
||
6 years ago
|
|
||
|
- name: "Destroy pod"
|
||
|
tags: cleanup
|
||
6 years ago
|
hosts: pods
|
||
6 years ago
|
gather_facts: no
|
||
6 years ago
|
vars:
|
||
|
ansible_connection: "local"
|
||
6 years ago
|
tasks:
|
||
|
- name: Destroy pod
|
||
|
k8s:
|
||
|
state: absent
|
||
|
definition:
|
||
|
apiVersion: v1
|
||
|
kind: Pod
|
||
|
metadata:
|
||
6 years ago
|
name: "{{inventory_hostname}}"
|
||
6 years ago
|
namespace: default
|