Compare commits

..

15 Commits

2 changed files with 28 additions and 89 deletions

View File

@ -56,6 +56,7 @@
#----------------------------------TEMPLATES---------------------------------- #----------------------------------TEMPLATES----------------------------------
#Only copy template files if there are templates defined in the incoming defintion dict #Only copy template files if there are templates defined in the incoming defintion dict
- set_fact: templates_Defined=0 - set_fact: templates_Defined=0
@ -80,7 +81,8 @@
loop_var: outer_item loop_var: outer_item
when: templates_Defined ==1 and outer_item.value.generic is not defined when: templates_Defined ==1 and outer_item.value.generic is not defined
tags: always tags: always
register: regular_template
notify: Restart container
#Copy templates form a generic dir, allow ansible to search #Copy templates form a generic dir, allow ansible to search
- name: "Generic template mappings for {{ container_Name }}" - name: "Generic template mappings for {{ container_Name }}"
#Files will be copied to the 'config' dir as defined by container_configDir, they will be stored using their template file name but with the '.j2' stripped #Files will be copied to the 'config' dir as defined by container_configDir, they will be stored using their template file name but with the '.j2' stripped
@ -91,7 +93,8 @@
loop_var: outer_item loop_var: outer_item
when: templates_Defined ==1 and outer_item.value.generic is defined when: templates_Defined ==1 and outer_item.value.generic is defined
tags: always tags: always
register: generic_template
notify: Restart container
- name: Append templated files to the mapping list - name: Append templated files to the mapping list
set_fact: set_fact:
#build a list to pass to docker containing the source of the file(As on disk on the host) and the destination mount within the container #build a list to pass to docker containing the source of the file(As on disk on the host) and the destination mount within the container
@ -132,6 +135,8 @@
loop_var: outer_item loop_var: outer_item
when: files_Defined == 1 and outer_item.value.generic is not defined and outer_item.value.src_text is not defined when: files_Defined == 1 and outer_item.value.generic is not defined and outer_item.value.src_text is not defined
tags: always tags: always
register: file_copy
notify: Restart container
#Copy files from a generic dir, allow ansible to search #Copy files from a generic dir, allow ansible to search
- name: "Generic File mappings for {{ container_Name }}" - name: "Generic File mappings for {{ container_Name }}"
#Files will be copied to the 'config' dir as defined by container_configDir, they will be stored using their file name #Files will be copied to the 'config' dir as defined by container_configDir, they will be stored using their file name
@ -142,6 +147,8 @@
loop_var: outer_item loop_var: outer_item
when: files_Defined == 1 and outer_item.value.generic is defined and outer_item.value.src_text is not defined when: files_Defined == 1 and outer_item.value.generic is defined and outer_item.value.src_text is not defined
tags: always tags: always
register: generic_copy
notify: Restart container
#Create files based on the suplied src_text param #Create files based on the suplied src_text param
- name: "Text based file creation for {{ container_Name }}" - name: "Text based file creation for {{ container_Name }}"
#Files will be copied to the 'config' dir as defined by container_configDir, they will be stored using their file name #Files will be copied to the 'config' dir as defined by container_configDir, they will be stored using their file name
@ -152,6 +159,8 @@
loop_var: outer_item loop_var: outer_item
when: files_Defined == 1 and outer_item.value.src_text is defined when: files_Defined == 1 and outer_item.value.src_text is defined
tags: always tags: always
register: text_copy
notify: Restart container
- name: Append static remote files to the mapping list - name: Append static remote files to the mapping list
set_fact: set_fact:
@ -208,6 +217,9 @@
tags: always tags: always
#----------------------------------/Check ENV---------------------------------- #----------------------------------/Check ENV----------------------------------
- name: Restart the container if fileChanged is defined
set_fact: containerRestart1='yes'
when: (containerRestart is defined and containerRestart=='yes') or (item.value.restart is defined and item.value.restart =='yes')
@ -221,7 +233,7 @@
recreate: "{{ item.value.recreate | default('false') }}" recreate: "{{ item.value.recreate | default('false') }}"
image: "{{ item.value.image }}" image: "{{ item.value.image }}"
state: "{{ item.value.start | default ('started') }}" state: "{{ item.value.start | default ('started') }}"
restart: "{{ item.value.restart | default ('no') }}" restart: "{{ containerRestart1 | default ('no') }}"
restart_policy: "{{ item.value.restart_policy | default ('always') }}" restart_policy: "{{ item.value.restart_policy | default ('always') }}"
purge_networks: "{{ item.value.purge_networks | default ('yes') }}" purge_networks: "{{ item.value.purge_networks | default ('yes') }}"
networks: "{{ net_checked }}" networks: "{{ net_checked }}"
@ -231,9 +243,17 @@
network_mode: "{{ item.value.network_mode | default ('default') }}" network_mode: "{{ item.value.network_mode | default ('default') }}"
shm_size: "{{ item.value.shm_size | default ('64M') }}" shm_size: "{{ item.value.shm_size | default ('64M') }}"
ports: "{{ item.value.ports | default ([]) }}" ports: "{{ item.value.ports | default ([]) }}"
cpu_period: "{{ item.value.cpu_period | default(0) }}"
cpu_quota: "{{ item.value.cpu_quota | default(0) }}"
cpu_shares: "{{ item.value.cpu_shares | default(0) }}"
cpus: "{{ item.value.cpus | default(0) }}"
cpuset_cpus: "{{ item.value.cpuset_cpus | default('') }}"
mem_limit: "{{ item.value.mem_limit | default(0) }}"
mem_reservation: "{{ item.value.mem_reservation | default(0) }}"
#log_driver: fluentd #log_driver: fluentd
#"{{item.value.ports | default ([json-file])}}" #"{{item.value.ports | default ([json-file])}}"
#log_options: #log_options:
# fluentd-sub-second-precision: true # fluentd-sub-second-precision: true
# tag: myservice # tag: myservice
tags: always tags: always

View File

@ -1,93 +1,12 @@
# - name: "Checking docker volume {{working_volume_name}}" # - name: "Checking docker volume {{working_volume_name}}"
# debug: msg="Checking docker volume {{working_volume_name}}" # debug: msg="Checking docker volume {{working_volume_name}}"
#----------------------------------CephFS Volume----------------------------------
- set_fact: base_volume_name="cephFS_"
tags: always
- name: Set working_volume_name(staticName not defined)
set_fact: working_volume_name="{{base_volume_name+container_Name + '_' + item.value.volumeName}}"
when: item.value.staticName is not defined
tags: always
- name: Set working_volume_name(staticName IS defined)
set_fact: working_volume_name={{item.value.staticName}}
when: item.value.staticName is defined
tags: always
- name: "Create {{ containerConfigDir }}/docker/cephFS"
file:
path: "{{containerConfigDir}}/docker/cephFS"
state: directory
recurse: no
when: item.value.type=="cephfs"
tags: always
- name: "Create {{ containerConfigDir }}/docker/configs"
file:
path: "{{containerConfigDir}}/docker/configs"
state: directory
recurse: no
when: item.value.type=="cephfs"
tags: always
- name: Add CephFS mount to fstab
lineinfile:
dest=/etc/fstab
backup=yes
state=present
line='none {{containerConfigDir}}/docker/cephFS fuse.ceph ceph.id=admin,_netdev,defaults 0 0'
register: fstab
tags: mount,always
when: item.value.type=="cephfs"
- name: Mount FSTab
shell: "mount -a"
args:
warn: false
when: fstab.changed
tags: mount,always
- name: "Checking docker volume "
debug: msg="CephFS user {{ cephFS_user }} secret {{ cephFS_secret }}"
when: item.value.type=="cephfs"
tags: always
- name: "Create docker volume - {{ working_volume_name }}"
docker_volume:
name: "{{ working_volume_name }}"
driver: n0r1skcom/docker-volume-cephfs
driver_options:
name="{{cephFS_user}}"
path="/container/{{working_volume_name}}"
secret="{{cephFS_secret}}"
monitors="{{ceph_Mons}}"
register: dockerVolume
tags: volume,always
when: item.value.type=="cephfs"
# This is needed so that when Docker goes to mount the volume, the folder it's looking for actually exists
- name: Create {{containerConfigDir}}/docker/cephFS/container/{{working_volume_name}}
file:
path: "{{containerConfigDir}}/docker/cephFS/container/{{working_volume_name}}"
state: directory
recurse: no
when: dockerVolume.changed
tags: volume,always
when: item.value.type=="cephfs"
- name: Append the volume to the container mapping list(mappings var defined in dockerContainer.yml)
set_fact:
mappings: "{{ mappings + [ working_volume_name + ':' + item.value.dest + ':' + item.value.params | default('rw') ] }}"
when: item.value.type=="cephfs"
tags: always
#----------------------------------/CephFS Volume----------------------------------
# ----------------------------------Local Volume---------------------------------- # ----------------------------------Local Volume----------------------------------
- set_fact: base_volume_name="local_" - set_fact: base_volume_name="local_"
- name: Set working_volume_name(staticName not defined) tags: always
- name: xSet working_volume_name(staticName not defined)
set_fact: working_volume_name="{{base_volume_name+container_Name + '_' + item.value.volumeName}}" set_fact: working_volume_name="{{base_volume_name+container_Name + '_' + item.value.volumeName}}"
when: item.value.staticName is not defined when: item.value.staticName is not defined
tags: always tags: always