-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2baa99b
commit 8826c9f
Showing
11 changed files
with
177 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
collections: | ||
- name: https://github.com/ansible-collections/community.general | ||
type: git | ||
- name: https://github.com/ansible-collections/community.docker | ||
type: git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ansible | ||
docker | ||
molecule | ||
molecule-plugins | ||
ansible-lint | ||
yamllint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
- name: Create docker networks | ||
loop: "{{ docker.networks }}" | ||
register: docker_network_template_config_result | ||
ansible.builtin.template: | ||
src: systemd/docker-network.service | ||
dest: "/etc/systemd/system/docker-network@{{ item.name }}" | ||
owner: root | ||
mode: "0644" | ||
|
||
- name: Template the docket-network script | ||
ansible.builtin.file: | ||
path: "/usr/local/bin/docker-network.sh" | ||
src: "docker-network.sh" | ||
mode: "0755" | ||
owner: root | ||
|
||
- name: Activate the docker network services | ||
loop: "{{ docker.networks }}" | ||
ansible.builtin.service: | ||
name: "docker-network@{{ item.name }}.service" | ||
state: started | ||
daemon_reload: yes | ||
|
||
- name: Reload docker-network@{{ item.name }}.service | ||
Check failure on line 25 in tasks/networks.yaml GitHub Actions / lintname[template]
|
||
loop: "{{ docker.networks }}" | ||
when: docker_network_template_config_result.changed | ||
ansible.builtin.service: | ||
name: docker-network@{{ item.name }}.service | ||
daemon_reload: yes | ||
state: reloaded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#! /usr/bin/env bash | ||
action=$1 | ||
network_name=$2 | ||
subnet=$3 | ||
driver=$4 | ||
|
||
tempfolder="/tmp/docker-networks" | ||
mkdir -p $tempfolder | ||
|
||
case $action in | ||
start) | ||
docker network create --driver=$driver --subnet=$subnet $network_name | ||
containers_in_network="$tempfolder/containers_in_network_$network_name" | ||
if [ -f "$containers_in_network" ]; then | ||
for i in `cat $containers_in_network`; do | ||
echo $i | ||
docker network connect $network_name $i; | ||
done; | ||
fi; | ||
rm -f $containers_in_network | ||
;; | ||
reload) | ||
containers_in_network=`docker network inspect -f '{{range .Containers}}{{.Name}} {{end}}' $network_name` | ||
for i in $containers_in_network; do | ||
docker network disconnect -f $network_name $i; | ||
done; | ||
docker network rm $network_name | ||
docker network create --driver=$driver --subnet=$subnet $network_name | ||
for i in $containers_in_network; do | ||
docker network connect $network_name $i; | ||
done; | ||
;; | ||
stop) | ||
containers_in_network=`docker network inspect -f '{{range .Containers}}{{.Name}} {{end}}' $network_name` | ||
echo $containers_in_network > "$tempfolder/containers_in_network_$network_name" | ||
for i in $containers_in_network; do | ||
docker network disconnect -f $network_name $i; | ||
done; | ||
docker network rm $network_name | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Unit] | ||
Requires=docker.service | ||
After=docker.service | ||
|
||
[Service] | ||
Restart=always | ||
RestartSec=10 | ||
TimeoutStopSec=60 | ||
ExecStart=/usr/local/bin/docker-network.sh start {{ item.name }} {{ item.subnet }} {{ item.driver | default("bridge") }} | ||
ExecReload=/usr/local/bin/docker-network.sh reload {{ item.name }} {{ item.subnet }} {{ item.driver | default("bridge") }} | ||
ExecStop=/usr/local/bin/docker-network.sh stop {{ item.name }} {{ item.subnet }} {{ item.driver | default("bridge") }} |