Skip to content

Commit 0548ae1

Browse files
committed
Update consul-values job
1 parent 34ce8a5 commit 0548ae1

5 files changed

Lines changed: 117 additions & 30 deletions

File tree

ansible/consul-values.yml

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,6 @@
22
- hosts: consul
33
vars_files:
44
- "group_vars/alpha-consul.yml"
5-
tasks:
6-
- name: make sure httplib2 is installed
7-
become: true
8-
apt: package=python-httplib2 state=present
9-
10-
- name: put values into consul
11-
run_once: true
12-
when: write_values is defined
13-
uri:
14-
method=PUT
15-
url=http://{{ ansible_default_ipv4.address }}:8500/v1/kv/{{ item.key }}
16-
body="{{ item.value }}"
17-
with_items: "{{ consul_seed }}"
18-
19-
- name: get values from consul
20-
tags: consul_values
21-
run_once: true
22-
when: read_values is defined
23-
uri:
24-
method=GET
25-
url=http://{{ ansible_default_ipv4.address }}:8500/v1/kv/{{ item.key }}
26-
with_items: "{{ consul_seed }}"
27-
register: values
28-
29-
- name: print values to screen
30-
tags: consul_values
31-
run_once: true
32-
when: read_values is defined
33-
debug: msg="{{ item.item.key }}" -> "{{ item.json[0].Value | b64decode }}"
34-
with_items: "{{ values.results }}"
5+
- "group_vars/alpha-consul-values.yml"
6+
roles:
7+
- role: k8-job

ansible/group_vars/all.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ docker_client_root: "{{ secrets_root }}/docker-client/"
1414
config_maps_path: "{{ opts_root }}/configMaps"
1515
services_path: "{{ opts_root }}/services"
1616
deployments_path: "{{ opts_root }}/deployments"
17+
jobs_path: "{{ opts_root }}/jobs"
1718
cron_jobs_path: "{{ opts_root }}/crons"
1819
volumes_path: "{{ opts_root }}/volumes"
1920
daemon_sets_path: "{{ opts_root }}/daemonSets"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: consul-update
2+
3+
container_image: tutum/curl
4+
container_tag: latest
5+
6+
advance_arg: true
7+
8+
container_run_args: >
9+
{% for item in consul_seed %} curl -X PUT http://consul:8500/v1/kv/{{ item.key }} --data {{ item.value }} && {% endfor %} echo Finished
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: create job folder
3+
file:
4+
state: directory
5+
path: "{{ jobs_path }}"
6+
7+
- name: create job yaml
8+
template:
9+
dest: "{{ jobs_path }}/{{ name }}.yml"
10+
src: job.yml
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: {{ name }}
5+
spec:
6+
template:
7+
metadata:
8+
labels:
9+
app: {{ name }}
10+
spec:
11+
imagePullSecrets:
12+
- name: {{ image_pull_secret_name }}
13+
hostname: {{ name }}
14+
restartPolicy: OnFailure
15+
containers:
16+
- image: {{ container_image }}:{{ container_tag }}
17+
imagePullPolicy: Always
18+
name: {{ name }}
19+
resources:
20+
requests:
21+
cpu: "250m"
22+
memory: "500M"
23+
limits:
24+
cpu: "1550m"
25+
memory: {{ memory_hard_limit | default("1500M") }}
26+
{% if post_start_command is defined %}
27+
lifecycle:
28+
postStart:
29+
exec:
30+
command: ["/bin/bash", "-c", "{{ post_start_command }}"]
31+
{% endif %}
32+
{% if container_run_args != '' %}
33+
args:
34+
{% if advance_arg is defined and advance_arg == true %}
35+
- bash
36+
- -c
37+
- "{{ container_run_args }}"
38+
{% else %}
39+
{% for arg in container_run_args.split(' ') %}
40+
- {{ arg }}
41+
{% endfor %}
42+
{% endif %}
43+
{% endif %}
44+
{% if container_envs is defined %}
45+
env:
46+
{% for env in container_envs %}
47+
{% if (env.value is defined and env.value != 'ansible_undefined') or env.valueFrom is defined %}
48+
- name: {{ env.name }}
49+
{% if env.value is defined %}
50+
value: "{{ env.value }}"
51+
{% endif %}
52+
{% if env.valueFrom is defined %}
53+
valueFrom:
54+
fieldRef:
55+
fieldPath: {{ env.valueFrom }}
56+
{% endif %}
57+
{% endif %}
58+
{% endfor %}
59+
{% endif %}
60+
{% if add_capabilities is defined %}
61+
securityContext:
62+
capabilities:
63+
add:
64+
{% for cap in add_capabilities %}
65+
- {{ cap }}
66+
{% endfor %}
67+
{% endif %}
68+
{% if hosted_ports is defined %}
69+
ports:
70+
{% for port in hosted_ports %}
71+
- containerPort: {{ port }}
72+
{% endfor %}
73+
{% endif %}
74+
{% if volume_mounts is defined %}
75+
volumeMounts:
76+
{% for volume in volume_mounts %}
77+
- name: {{ volume.name }}
78+
mountPath: {{ volume.path }}
79+
{% endfor %}
80+
{% endif %}
81+
{% if volume_mounts is defined %}
82+
volumes:
83+
{% for volume in volume_mounts %}
84+
- name: {{ volume.name }}
85+
{% if volume.kind == "configMap" %}
86+
configMap:
87+
name: {{ volume.name }}
88+
{% endif %}
89+
{% if volume.kind == "persistent" %}
90+
persistentVolumeClaim:
91+
claimName: {{ volume.name }}
92+
{% endif %}
93+
{% endfor %}
94+
{% endif %}

0 commit comments

Comments
 (0)