Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: changed swarm init move from cloud-config to swarm.yml play #30

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions generators/ansible-do/templates/ansible/stack/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ setup.portainer:
@printf "\033[0;3ansible/2m>>> Set up portainer\033[0m\n"
ansible-playbook plays/portainer.yml

setup.swarm:
@printf "\033[0;3ansible/2m>>> Set up docker swarm\033[0m\n"
ansible-playbook plays/swarm.yml

setup.traefik:
@printf "\033[0;3ansible/2m>>> Set up traefik\033[0m\n"
ansible-playbook plays/traefik.yml
Expand Down
22 changes: 22 additions & 0 deletions generators/ansible-do/templates/ansible/stack/plays/swarm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: Setup docker swarm
hosts: all
tasks:
- name: install python docker module
ansible.builtin.pip:
name: docker

- name: Fetch IP of the droplet
uri:
url: http://169.254.169.254/metadata/v1/interfaces/private/0/ipv4/address
return_content: yes
register: metadata_response

- name: Set IP as a fact
set_fact:
private_ip: "{{ metadata_response.content }}"

- name: Check/init Swarm
docker_swarm:
state: present
advertise_addr: "{{ private_ip }}"
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ users:
{% endfor %}
{% endfor %}

package_update: true
package_upgrade: true
package_reboot_if_required: true

packages:
- python3-pip

{% for package in packages %}
- {{ package }}
{% endfor %}

package_update: true
package_upgrade: true
package_reboot_if_required: true

bootcmd:
{% for volume in volumes %}
- mkdir {{ volume.path }}
Expand All @@ -43,5 +45,4 @@ runcmd:
{% for volume
in volumes %}
- chown -R {{ volume.user }}:{{ volume.group }} {{ volume.path }}
{% endfor %}
- docker swarm init --advertise-addr $(curl -s http://169.254.169.254/metadata/v1/interfaces/private/0/ipv4/address)
{% endfor %}