This commit is contained in:
Pavel Guzaev
2024-03-09 17:36:50 +05:00
commit 431b4f5cfd
44 changed files with 3239 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
# NetPlan file for internal network
hetzner_server_netplan_int_net: /etc/netplan/01-network-manager.yaml
hetzner_server_server_location: hel1-dc2
# hetzner_server_server_location: fsn1-dc14
# default gateway
hetzner_server_gw_ip: 10.106.100.1

View File

@@ -0,0 +1,6 @@
---
- name: netplan apply
tags: netplan
command: ssh {{ ip_addr }} -oStrictHostKeyChecking=no "netplan apply"
async: 1
poll: 0

View File

@@ -0,0 +1,65 @@
---
- name: GET APPS NUMBER
shell: hcloud server list -o columns=name | grep sd-apps[[:digit:]] | sed s/[^0-9]//g
register: _nodes
- set_fact:
nodes: "{{ _nodes.stdout_lines }}"
- name: GET NEXT NODE NUMBER
set_fact: max_node_id="{{ nodes | sort | last }}"
- debug:
msg: "Next Node id is {{ max_node_id | int + 1 }}"
- name: "Create new sd-apps server with next number {{ max_node_id | int + 1 }}"
shell: hcloud server create --datacenter "{{ hetzner_server_server_location }}" --image ubuntu-20.04 --ssh-key ansible,manager,pguzaev@naumen.ru --network 1127862 --start-after-create --type cpx51 --name "sd-apps{{ max_node_id | int + 1 }}-presale"
register: _status
- debug:
msg: "Status is {{ _status.stdout_lines }}"
- set_fact:
ext_ip_addr: "{{ _status.stdout_lines[3] }}"
- debug:
msg: "External ip address is {{ ext_ip_addr.split()[1] }}"
- name: Wait ssh avalaible
wait_for:
host: "{{ ext_ip_addr.split()[1] }}"
port: "22"
state: started # Port should be open
delay: 10 # No wait before first check (sec)
timeout: 240 # Stop checking after timeout (sec)
ignore_errors: no
- name: GET APPS
shell: hcloud server describe -o json "sd-apps{{ max_node_id | int + 1 }}-presale"
register: _result
- set_fact:
private_net: "{{ (_result.stdout | from_json).private_net }}"
- set_fact:
ip_addr: "{{ private_net[0]['ip'] }}"
- name: GET APPS
shell: hcloud server ssh sd-apps{{ max_node_id | int + 1 }}-presale -oStrictHostKeyChecking=no ifconfig | awk '/{{ ip_addr }}/ {print $1}' RS="\n\n"
register: _if_int
- set_fact:
if_int: "{{ _if_int.stdout }}"
- debug:
msg: "internal iface is {{ if_int }} and has ip adress is {{ ip_addr }}"
- name: Netplan configure rules
template:
src: 01-network-manager.yaml.js2
dest: "/tmp/sd-apps{{ max_node_id | int + 1 }}-presale.yaml"
- name: Set Netplan
shell: scp -oStrictHostKeyChecking=no "/tmp/sd-apps{{ max_node_id | int + 1 }}-presale.yaml" "{{ ip_addr }}:{{ hetzner_server_netplan_int_net }}"
notify:
- netplan apply

View File

@@ -0,0 +1,23 @@
# This file is generated from ansible autogeneration scripts
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
{{ if_int }}
dhcp4: true
nameservers:
addresses:
- 192.168.224.7
- 192.168.240.7
- 91.232.196.12
search:
- office0.naumen.ru
routes:
- to: 192.168.0.0/16
via: 10.106.100.1
- to: 172.16.0.0/16
via: 10.106.100.1
- to: 10.0.0.0/8
via: {{ hetzner_server_gw_ip }}