routing working
This commit is contained in:
@@ -19,7 +19,22 @@ services:
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
replicas: 1
|
||||
|
||||
# db:
|
||||
# image: postgres
|
||||
# restart: always
|
||||
# environment:
|
||||
# POSTGRES_PASSWORD: example
|
||||
# volumes:
|
||||
# - pgdata:/var/lib/postgresql/data
|
||||
# networks:
|
||||
# - portainer_net
|
||||
# deploy:
|
||||
# placement:
|
||||
# constraints:
|
||||
# - node.role == manager
|
||||
# restart_policy:
|
||||
# condition: on-failure
|
||||
# replicas: 1
|
||||
volumes:
|
||||
portainer_data:
|
||||
external: true
|
||||
|
||||
@@ -12,3 +12,5 @@ docker_packages_state: present
|
||||
docker_users:
|
||||
- vagrant
|
||||
|
||||
# docker_hub_username: "{{ lookup('env_file', '.env', 'DOCKER_HUB_USERNAME') }}"
|
||||
# docker_hub_password: "{{ lookup('env_file', '.env', 'DOCKER_HUB_PASSWORD') }}"
|
||||
@@ -1,3 +1,14 @@
|
||||
|
||||
- name: Load environment variables from .env file
|
||||
include_vars:
|
||||
file: .env.yml
|
||||
name: env_vars
|
||||
|
||||
- name: Set Docker Hub credentials from env vars
|
||||
set_fact:
|
||||
docker_hub_username: "{{ env_vars.DOCKER_HUB_USERNAME }}"
|
||||
docker_hub_password: "{{ env_vars.DOCKER_HUB_PASSWORD }}"
|
||||
|
||||
- name: Check memory and swap usage
|
||||
command: free -m
|
||||
register: memory_info
|
||||
@@ -6,6 +17,14 @@
|
||||
- name: apt update
|
||||
ansible.builtin.apt:
|
||||
update_cache: yes
|
||||
|
||||
- name: install packages
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- jq
|
||||
- vim
|
||||
- curl
|
||||
state: present
|
||||
|
||||
- name: Ensure Python pip is installed
|
||||
package:
|
||||
@@ -35,3 +54,38 @@
|
||||
until: docker_service.status.ActiveState == "active"
|
||||
retries: 10
|
||||
delay: 20
|
||||
|
||||
# - name: Create Docker config directory for vagrant user
|
||||
# file:
|
||||
# path: /home/vagrant/.docker
|
||||
# state: directory
|
||||
# mode: '0700'
|
||||
# owner: vagrant
|
||||
# group: vagrant
|
||||
|
||||
- name: Login to Docker Hub as vagrant user
|
||||
community.docker.docker_login:
|
||||
username: "{{ docker_hub_username }}"
|
||||
password: "{{ docker_hub_password }}"
|
||||
# config_path: "/home/vagrant/.docker"
|
||||
reauth: true
|
||||
become_user: vagrant
|
||||
when: docker_hub_username is defined and docker_hub_password is defined
|
||||
register: docker_login_result
|
||||
|
||||
- name: Debug Docker Hub credentials
|
||||
debug:
|
||||
msg: |
|
||||
Username: {{ docker_hub_username }}
|
||||
Password: {{ docker_hub_password }}
|
||||
|
||||
- name: Debug Docker login result
|
||||
debug:
|
||||
msg: |
|
||||
=== DOCKER LOGIN RESULT ===
|
||||
Changed: {{ docker_login_result.changed }}
|
||||
Failed: {{ docker_login_result.failed | default(false) }}
|
||||
Message: {{ docker_login_result.msg | default('No message') }}
|
||||
Login successful: {{ docker_login_result.login_successful | default('Unknown') }}
|
||||
Full result: {{ docker_login_result }}
|
||||
# when: docker_hub_username is defined and docker_hub_password is defined
|
||||
@@ -33,6 +33,7 @@
|
||||
state: present
|
||||
advertise_addr: "{{ ansible_eth1.ipv4.address }}"
|
||||
listen_addr: "{{ ansible_eth1.ipv4.address }}"
|
||||
|
||||
- name: print listen addr
|
||||
debug:
|
||||
msg: "{{ ansible_eth1.ipv4.address }}"
|
||||
|
||||
@@ -20,27 +20,28 @@
|
||||
set_fact:
|
||||
worker_token: "{{ worker_token_file.content | b64decode | trim }}"
|
||||
|
||||
- name: Debug all relevant variables
|
||||
debug:
|
||||
msg: |
|
||||
=== SWARM JOIN DEBUG INFO ===
|
||||
Current host: {{ inventory_hostname }}
|
||||
Current host IP: {{ ansible_host }}
|
||||
# - name: Debug all relevant variables
|
||||
# debug:
|
||||
# msg: |
|
||||
# === SWARM JOIN DEBUG INFO ===
|
||||
# Current host: {{ inventory_hostname }}
|
||||
# Current host IP: {{ ansible_host }}
|
||||
# ansible_eth1={{ ansible_eth1.ipv4.address }}
|
||||
|
||||
Master group hosts: {{ groups['swarm_master'] }}
|
||||
First master: {{ groups['swarm_master'][0] }}
|
||||
|
||||
Master hostvars:
|
||||
- ansible_host: {{ hostvars[groups['swarm_master'][0]]['ansible_host'] }}
|
||||
- inventory_hostname: {{ hostvars[groups['swarm_master'][0]]['inventory_hostname'] }}
|
||||
|
||||
Remote address calculation:
|
||||
- Raw master ansible_host: {{ hostvars[groups['swarm_master'][0]]['ansible_host'] }}
|
||||
- Fallback to hostname: {{ groups['swarm_master'][0] }}
|
||||
- Final address: {{ hostvars[groups['swarm_master'][0]]['ansible_host'] | default(groups['swarm_master'][0]) }}
|
||||
- With port: {{ hostvars[groups['swarm_master'][0]]['ansible_host'] | default(groups['swarm_master'][0]) }}:2377
|
||||
|
||||
Join token (first 10 chars): {{ worker_token[:10] }}...
|
||||
# Master group hosts: {{ groups['swarm_master'] }}
|
||||
# First master: {{ groups['swarm_master'][0] }}
|
||||
|
||||
# Master hostvars:
|
||||
# - ansible_host: {{ hostvars[groups['swarm_master'][0]]['ansible_host'] }}
|
||||
# - inventory_hostname: {{ hostvars[groups['swarm_master'][0]]['inventory_hostname'] }}
|
||||
|
||||
# Remote address calculation:
|
||||
# - Raw master ansible_host: {{ hostvars[groups['swarm_master'][0]]['ansible_host'] }}
|
||||
# - Fallback to hostname: {{ groups['swarm_master'][0] }}
|
||||
# - Final address: {{ hostvars[groups['swarm_master'][0]]['ansible_host'] | default(groups['swarm_master'][0]) }}
|
||||
# - With port: {{ hostvars[groups['swarm_master'][0]]['ansible_host'] | default(groups['swarm_master'][0]) }}:2377
|
||||
|
||||
# Join token (first 10 chars): {{ worker_token[:10] }}...
|
||||
|
||||
- name: Gather master facts
|
||||
ansible.builtin.setup:
|
||||
@@ -48,21 +49,23 @@
|
||||
run_once: true
|
||||
register: master_facts
|
||||
|
||||
- name: Debug master hostvars
|
||||
debug:
|
||||
msg: |
|
||||
Master hostvars keys: {{ hostvars[groups['swarm_master'][0]].keys() | list }}
|
||||
Master ansible_eth1: {{ hostvars[groups['swarm_master'][0]].ansible_eth1 | default('Not available') }}
|
||||
Master node: {{ groups['swarm_master'][0] }}
|
||||
Master ansible_default_ipv4: {{ hostvars[groups['swarm_master'][0]] }}
|
||||
Master ansible_default_ipv4: {{ master_facts.ansible_facts }}
|
||||
FINAL IP: {{ master_facts.ansible_facts ['ansible_eth1']['ipv4']['address'] }}
|
||||
# - name: Debug master hostvars
|
||||
# debug:
|
||||
# msg: |
|
||||
# Master hostvars keys: {{ hostvars[groups['swarm_master'][0]].keys() | list }}
|
||||
# Master ansible_eth1: {{ hostvars[groups['swarm_master'][0]].ansible_eth1 | default('Not available') }}
|
||||
# Master node: {{ groups['swarm_master'][0] }}
|
||||
# Master ansible_default_ipv4: {{ hostvars[groups['swarm_master'][0]] }}
|
||||
# Master ansible_default_ipv4: {{ master_facts.ansible_facts }}
|
||||
# remote_addrs: {{ master_facts.ansible_facts ['ansible_eth1']['ipv4']['address'] }}
|
||||
# advertise_addr: {{ ansible_eth1.ipv4.address }}
|
||||
|
||||
- name: Add nodes
|
||||
community.docker.docker_swarm:
|
||||
state: join
|
||||
join_token: "{{ worker_token }}"
|
||||
remote_addrs:
|
||||
- "{{ master_facts.ansible_facts ['ansible_eth1']['ipv4']['address'] }}:2377"
|
||||
- "{{ master_facts.ansible_facts['ansible_eth1']['ipv4']['address'] }}:2377"
|
||||
advertise_addr: "{{ ansible_eth1.ipv4.address }}"
|
||||
listen_addr: "{{ ansible_eth1.ipv4.address }}:2377"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
- name: Deploy Portainer stack from compose file
|
||||
community.docker.docker_stack:
|
||||
name: portainer
|
||||
name: mgmt
|
||||
state: present
|
||||
compose:
|
||||
- "{{ lookup('file', 'files/docker-base-stack.yml') | from_yaml }}"
|
||||
Reference in New Issue
Block a user