Compare commits

...

2 Commits
master ... main

Author SHA1 Message Date
Cory Hawkvelt 1b95015c0f cpu and memory limits 2024-07-03 10:27:22 +09:30
Cory Hawkvelt 58d4ca0cf7 Added CPU and memoty limits 2024-07-03 10:22:31 +09:30
1 changed files with 34 additions and 63 deletions

View File

@ -217,72 +217,43 @@
tags: always tags: always
#----------------------------------/Check ENV---------------------------------- #----------------------------------/Check ENV----------------------------------
- name: Setup default values for this container - name: Restart the container if fileChanged is defined
set_fact: set_fact: containerRestart1='yes'
default: when: (containerRestart is defined and containerRestart=='yes') or (item.value.restart is defined and item.value.restart =='yes')
name: "{{ container_Name }}"
hostname: "{{ item.value.hostname | default(container_Name) }}"
command: "{{ item.value.command | default('') }}"
pull: "{{ item.value.pull | default('false') }}"
recreate: "{{ item.value.recreate | default('false') }}"
image: "{{ item.value.image }}"
state: "{{ item.value.start | default ('started') }}"
restart: "{{ item.value.restart | default ('no') }}"
restart_policy: "{{ item.value.restart_policy | default ('always') }}"
purge_networks: "{{ item.value.purge_networks | default ('yes') }}"
networks: "{{ net_checked }}"
volumes: "{{ mappings }}"
env: "{{ env_checked }}"
privileged: "{{ item.value.privileged | default ('no') }}"
network_mode: "{{ item.value.network_mode | default ('default') }}"
shm_size: "{{ item.value.shm_size | default ('64M') }}"
ports: "{{ item.value.ports | default ([]) }}"
tags: always
- name: Setup devices_override blank
set_fact:
devices_override:
tags: always
- name: Setup ulimit_override blank
set_fact:
ulimit_override:
tags: always
#----------Merge ulimits--------------
- name: Apply conditional override
set_fact:
ulimit_override:
ulimits: "{{ item.value.ulimits }}"
when: item.value.ulimits is defined
tags: always
- name: Merge the two lists
set_fact:
ulimits_merged: "{{ default | combine(ulimit_override, recursive=true) }}"
tags: always
#----------Merge devices--------------
- name: Apply conditional override
set_fact:
devices_override:
devices: "{{ item.value.devices }}"
when: item.value.devices is defined
tags: always
- name: Merge the two lists
set_fact:
final_merged: "{{ ulimits_merged | combine(devices_override, recursive=true) }}"
tags: always
- name: debug value
debug:
msg: "{{final_merged}}"
tags: always
- name: "Container {{ container_Name }}" - name: "Container {{ container_Name }}"
become: true become: yes
docker_container: "{{ final_merged }}" docker_container:
name: "{{ container_Name }}"
hostname: "{{ item.value.hostname | default(container_Name) }}"
command: "{{ item.value.command | default('') }}"
pull: "{{ item.value.pull | default('false') }}"
recreate: "{{ item.value.recreate | default('false') }}"
image: "{{ item.value.image }}"
state: "{{ item.value.start | default ('started') }}"
restart: "{{ containerRestart1 | default ('no') }}"
restart_policy: "{{ item.value.restart_policy | default ('always') }}"
purge_networks: "{{ item.value.purge_networks | default ('yes') }}"
networks: "{{ net_checked }}"
volumes: "{{ mappings }}"
env: "{{ env_checked }}"
privileged: "{{ item.value.privileged | default ('no') }}"
network_mode: "{{ item.value.network_mode | default ('default') }}"
shm_size: "{{ item.value.shm_size | default ('64M') }}"
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
#"{{item.value.ports | default ([json-file])}}"
#log_options:
# fluentd-sub-second-precision: true
# tag: myservice
tags: always tags: always