Setup network too
ci/woodpecker/push/build Pipeline was successful Details

This commit is contained in:
Nikolai Rodionov 2024-05-03 18:11:45 +02:00
parent 6b66d8cc25
commit 0f7942843b
Signed by: allanger
GPG Key ID: 0AA46A90E25592AD
5 changed files with 61 additions and 34 deletions

View File

@ -54,13 +54,27 @@
api_token: "{{ api_token }}"
ssh_keys:
- "{{ customer }}-{{ env }}"
firewalls:
- admin
private_networks:
- "{{ customer }}-{{ env }}"
location: hel1
register: server_data
# --------------------------------------------------------
# -- Create volumes
# --------------------------------------------------------
- name: Create a volume
hetzner.hcloud.hcloud_volume:
api_token: "{{ api_token }}"
name: "{{ customer }}-{{ env }}"
size: 40
server: "{{ customer }}-{{ env }}"
state: "{{ state }}"
# ----------------------------------------------------
# -- Currently, I think it should be configured by
# -- other ansible playbooks, so automount is false
# ----------------------------------------------------
automount: false
register: volumes_data
# --------------------------------------------------------
# -- Create floating IPs
# --------------------------------------------------------
- name: Create a floating IP
@ -85,4 +99,6 @@
dest: "{{ output_dir }}/inventory.yaml"
vars:
ipv4_address: "{{ server_data.hcloud_server.ipv4_address }}"
ipv4_entrypoint: "{{ floating_ips_data.hcloud_floating_ip.ip }}"
cluster_name: "{{ customer }}-{{ env }}"
volume_device_name: "{{ volumes_data.hcloud_volume.linux_device }}"

View File

@ -3,6 +3,12 @@ servers:
{{ ipv4_address }}:
vars:
ansible_ssh_private_key_file: /tmp/outputs/ssh_key
service_entrypoint: {{ ipv4_address }}
user_entrypoint: {{ ipv4_entrypoint }}
volumes:
- device: {{ volume_device_name }}
dir: /softplayer/data
fstype: ext4
k3s_cluster:
children:
server:

View File

@ -19,7 +19,17 @@
tags:
- system
tasks:
- name: Setup network
ansible.builtin.import_tasks: ./tasks/network.yaml
- name: Install packages
ansible.builtin.import_tasks: ./tasks/packages.yaml
- name: Setup sysctl
ansible.builtin.import_tasks: ./tasks/sysctl.yaml
- name: Setup volumes
ansible.builtin.import_tasks: ./tasks/volumes.yaml
handlers:
- name: Restart NetworkManager
ansible.builtin.service:
name: NetworkManager
state: restarted

View File

@ -1,32 +0,0 @@
---
- name: Netplan config
when: ansible_distribution == 'Ubuntu'
block:
- name: Update the netplan config
become: true
ansible.builtin.template:
src: templates/60-floating-ip.j2
dest: /etc/netplan/60-floating-ip.yaml
owner: root
group: root
mode: '0600'
vars:
publicIP: 195.201.250.50
- name: Apply a new config
become: true
ansible.builtin.shell: netplan apply
- name: Ifcfg onfig
when: ansible_distribution == 'Rocky'
block:
- name: Update the ifcfg config
notify: Restart the network service
become: true
ansible.builtin.template:
src: templates/ifcfg-eth0:1.j2
dest: /etc/sysconfig/network-scripts/ifcfg-eth0:1
owner: root
group: root
mode: '0600'
vars:
publicIP: 195.201.249.91

View File

@ -0,0 +1,27 @@
---
- name: Check that the deprecated netconfig file exists
become: true
stat:
path: /etc/sysconfig/network-scripts/ifcfg-eth0
register: deprecated_netconf
- name: Migrate to newer NetworkManager config
when: deprecated_netconf.stat.exists
become: true
ansible.builtin.command: nmcli connection migrate
- name: Setup a service endpoint ipv4
become: true
notify:
- Restart NetworkManager
community.general.nmcli:
conn_name: 'System eth0'
ifname: eth0
type: ethernet
ip4:
- "{{ service_entrypoint }}/32"
- "{{ user_entrypoint }}/32"
method4: auto
mac: "{{hostvars[inventory_hostname].ansible_default_ipv4.macaddress}}"
autoconnect: true
state: present