Files
demo/ansible/playbook/roles/hetzner_server/tasks/main.yml
Pavel Guzaev 431b4f5cfd all demo
2024-03-09 17:36:50 +05:00

66 lines
2.1 KiB
YAML

---
- 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