-
Notifications
You must be signed in to change notification settings - Fork 28
/
centos7-elasticsearch-image.yml
77 lines (77 loc) · 3.1 KB
/
centos7-elasticsearch-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
- hosts: localhost
vars:
base_image: "centos:7.9.2009"
base_command: "sleep 900"
tagrepo: "localhost:5000/systemctl"
tagname: "elasticsearch"
tasks:
- name: name of setup container
set_fact:
container1: "{{ tagname.replace('/','-') + '-build-' + lookup('pipe', 'echo $PPID') }}"
- debug: var=setup_container
- name: remove setup container
command: docker rm -f '{{ container1 }}'
ignore_errors: yes
- name: start docker mirror package repo
shell: ./docker_mirror.py start {{base_image}} -a
register: mirror
- name: start setup container
command: docker run -d --rm=true {{ mirror.stdout_lines[0] }} \
--name "{{ container1 }}" "{{ base_image }}" {{base_command}}
- name: attach setup container
add_host:
hostname: '{{ container1 }}'
ansible_connection: 'docker'
ansible_user: "root"
# ansible_python_interpreter: /usr/bin/python
- name: gather facts on it
delegate_to: '{{ container1 }}'
setup:
gather_subset: "all"
###############################################################################
- name: setup systemctl.py
delegate_to: '{{ container1 }}'
import_role:
name: "deployment-systemctl-replacement"
vars:
deployment_docker: yes
- name: setup the container
delegate_to: '{{ container1 }}'
import_role:
name: "elasticsearch"
###############################################################################
###### find elasticsearch version and use it to tag the resulting image #######
###############################################################################
- name: software package
set_fact:
software_package: '{{ elasticsearch_rpm.split("-")[0] }}'
- name: software version
delegate_to: '{{ container1 }}'
shell: "rpm -q --info {{ software_package }} | sed -e '/Version *:/!d' -e 's/.*: *//' -e q"
register: software_version_found
- debug: var=software_version_found
- name: image version
set_fact:
image_version: "{{ software_version_found.stdout | trim }}"
- debug: var=image_version
- name: image name
set_fact:
image_name2: '{{ tagrepo + "/" + tagname + "/" + base_image.replace(":","-") }}'
image_name1: '{{ tagrepo + "/" + tagname }}'
- name: commit the container
command: docker commit \
-c 'CMD ["/usr/bin/systemctl"]' \
'{{ container1 }}' '{{ image_name2 }}:{{ image_version }}'
- name: latest image 2
command: docker tag \
'{{ image_name2 }}:{{ image_version }}' '{{ image_name2 }}'
- name: latest image 1
command: docker tag \
'{{ image_name2 }}:{{ image_version }}' '{{ image_name1 }}'
#######################################################################
- name: remove setup container
command: docker rm -f '{{ container1 }}'
ignore_errors: yes
- name: cleanup images
shell: 'docker images --filter=dangling=true --format "{{ "{{" }} .ID {{ "}}" }}" | xargs --no-run-if-empty docker rmi'
ignore_errors: yes