container: Support static ip for container
This commit is contained in:
@@ -4,6 +4,7 @@ container_user: ""
|
||||
container_mounts: []
|
||||
container_publish_ports: []
|
||||
container_networks: []
|
||||
container_ip: ""
|
||||
container_secrets: []
|
||||
container_env: {}
|
||||
container_auto_start: true
|
||||
|
||||
@@ -115,6 +115,11 @@ argument_specs:
|
||||
required: false
|
||||
default: []
|
||||
elements: str
|
||||
container_ip:
|
||||
description: IPv4 address for the container in the first network defined in container_networks
|
||||
type: str
|
||||
required: false
|
||||
default: ""
|
||||
container_secrets:
|
||||
description: A list of secrets available to the container as file or environment variable
|
||||
type: list
|
||||
|
||||
@@ -15,10 +15,16 @@
|
||||
name: network
|
||||
vars:
|
||||
network_name: "{{ network }}"
|
||||
network_subnet: >-
|
||||
{{
|
||||
container_ip | ansible.utils.ipsubnet(24)
|
||||
if (container_ip | length > 0 and network_index == 0) else ''
|
||||
}}
|
||||
when: network_created_networks is not defined or network not in network_created_networks
|
||||
loop: "{{ container_networks }}"
|
||||
loop_control:
|
||||
loop_var: network
|
||||
index_var: network_index
|
||||
|
||||
- name: Create volumes for container {{ container_name }}
|
||||
ansible.builtin.include_role:
|
||||
@@ -45,7 +51,7 @@
|
||||
command: "{{ container_command or omit }}"
|
||||
user: "{{ container_user or omit }}"
|
||||
mount: "{{ _container_mounts | map('items') | map('map', 'join', '=') | map('join', ',') }}"
|
||||
network: "{{ container_networks | map('regex_replace', '$', '.network') }}"
|
||||
network: "{{ _container_networks_with_ip }}"
|
||||
publish: "{{ container_publish_ports }}"
|
||||
secrets: "{{ _container_secrets }}"
|
||||
env: "{{ container_env }}"
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
---
|
||||
_container_image: "{{ container_image | replace('/', '_') ~ '.image' }}"
|
||||
|
||||
_container_networks: "{{ container_networks | map('regex_replace', '$', '.network') }}"
|
||||
_container_networks_with_ip: >-
|
||||
{{
|
||||
[
|
||||
_container_networks[0] ~ (
|
||||
':ip=' ~ container_ip if container_ip | length > 0 else ''
|
||||
)
|
||||
]
|
||||
+ _container_networks[1:]
|
||||
}}
|
||||
|
||||
_container_volumes: "{{ container_mounts | selectattr('type', '==', 'volume') }}"
|
||||
|
||||
_container_mount_sources: "{{ container_mounts | map(attribute='source') }}"
|
||||
|
||||
Reference in New Issue
Block a user