Merge infra and k3 into one directory again
Since I don't have multiple terraform steps anymore it simply doesn't make sense to me anymore to split all tasks into separate folders. Instead I try to be as clear as possible in the README to make it easy to follow the structure in the future without too much headache.
This commit is contained in:
2
roles/server-setup/defaults/main.yml
Normal file
2
roles/server-setup/defaults/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
ip_masquerade_path: /etc/networkd-dispatcher/routable.d
|
||||
ip_masquerade_script: 10-eth0-post-up
|
||||
7
roles/server-setup/handlers/main.yml
Normal file
7
roles/server-setup/handlers/main.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
- name: Restart sshd
|
||||
service:
|
||||
name: ssh
|
||||
state: restarted
|
||||
|
||||
- name: Start ip-masquerade
|
||||
script: "{{ ip_masquerade_path }}/{{ ip_masquerade_script }}"
|
||||
50
roles/server-setup/tasks/main.yml
Normal file
50
roles/server-setup/tasks/main.yml
Normal file
@@ -0,0 +1,50 @@
|
||||
- name: Set facts for target SSH-connection
|
||||
set_fact:
|
||||
target_ansible_port: "{{ ansible_port }}"
|
||||
|
||||
- name: Check if SSH-connection is already adjusted
|
||||
ping:
|
||||
ignore_errors: "yes"
|
||||
ignore_unreachable: "yes"
|
||||
register: target_ssh
|
||||
|
||||
- name: Set ansible_port to 22 when SSH-connection is not adjusted
|
||||
set_fact:
|
||||
ansible_port: "22"
|
||||
when: target_ssh.unreachable is defined and
|
||||
target_ssh.unreachable == True
|
||||
|
||||
- name: Check if initial SSH-connection is active
|
||||
ping:
|
||||
when: target_ssh.unreachable is defined and
|
||||
target_ssh.unreachable == True
|
||||
|
||||
- name: Set SSH-port to 1022
|
||||
lineinfile:
|
||||
path: /etc/ssh/sshd_config
|
||||
regexp: '^#?\s*Port\s+[0-9]+$'
|
||||
line: Port 1022
|
||||
notify: "Restart sshd"
|
||||
when: target_ssh.unreachable is defined and
|
||||
target_ssh.unreachable == True
|
||||
|
||||
- name: Reset ansible_port to configured value
|
||||
set_fact:
|
||||
ansible_port: "{{ target_ansible_port }}"
|
||||
when: target_ssh.unreachable is defined and
|
||||
target_ssh.unreachable == True
|
||||
|
||||
- name: Run deferred setup to gather facts
|
||||
setup:
|
||||
|
||||
- name: Ensure routable.d path to masquerade ips
|
||||
file:
|
||||
path: "{{ ip_masquerade_path }}"
|
||||
state: directory
|
||||
|
||||
- name: Configure NAT to masquerade ips
|
||||
template:
|
||||
src: ip-masquerade.sh.j2
|
||||
dest: "{{ ip_masquerade_path }}/{{ ip_masquerade_script }}"
|
||||
mode: u=rwx,g=rx,o=rx
|
||||
notify: "Start ip-masquerade"
|
||||
4
roles/server-setup/templates/ip-masquerade.sh.j2
Normal file
4
roles/server-setup/templates/ip-masquerade.sh.j2
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
echo 1 > /proc/sys/net/ipv4/ip_forward
|
||||
iptables -t nat -A POSTROUTING -s {{network_cidr}} -o eth0 -j MASQUERADE
|
||||
|
||||
Reference in New Issue
Block a user