Browse Source

merge lxd_host.yml into main role

master
cinnaboot 5 years ago
parent
commit
b61f90e5c6
  1. 2
      all.yml
  2. 1
      roles/dokuwiki/tasks/main.yml
  3. 77
      roles/lxd_host/tasks/lxd_host.yml
  4. 79
      roles/lxd_host/tasks/main.yml

2
all.yml

@ -1,6 +1,6 @@
--- ---
- hosts: lxd_host - hosts: lxd_host
tags: lxd_host tags: container_install
roles: roles:
- lxd_host - lxd_host

1
roles/dokuwiki/tasks/main.yml

@ -15,6 +15,7 @@
import_tasks: dokuwiki.yml import_tasks: dokuwiki.yml
- name: backup block - name: backup block
tags: backup
include_tasks: backup.yml include_tasks: backup.yml
vars: vars:
output: /tmp/ output: /tmp/

77
roles/lxd_host/tasks/lxd_host.yml

@ -1,77 +0,0 @@
---
# TODO: use template for lxd-init --preseed
- name: copy ssh pubkey from controller to lxd host
copy:
src: "{{ lookup('env', 'HOME') + '/.ssh/id_rsa.pub' }}"
dest: "{{ tmp_pubkey }}"
# TODO: might make sense to add a cache redirect for alpine packages
- include_tasks: tasks/container_install.yml
tags: container_install
vars:
container_name: "{{ item }}"
container_sshd_port: "{{ hostvars[item]['ansible_port'] }}"
container_ip: "{{ hostvars[item]['internal_ip'] }}"
tmp_sshd_config: "/tmp/sshd_config_{{ item }}"
with_items: "{{ groups['containers'] }}"
- name: install iptables and iptables-persistent
tags: routing
become: yes
apt:
name: [iptables, iptables-persistent]
state: present
when: do_routing
- name: add DNAT rules for containers
tags: routing
iptables:
table: nat
chain: PREROUTING
in_interface: "{{ host_iface }}"
protocol: tcp
match: tcp
source: "{{ host_cidr }}"
jump: DNAT
destination_port: "{{ hostvars[item]['ansible_port'] }}"
to_destination: "{{ hostvars[item]['internal_ip'] }}"
become: yes
with_items: "{{ groups['containers'] }}"
when: do_routing
- name: save DNAT rules on lxd host
tags: routing
become: yes
community.general.iptables_state:
table: nat
state: saved
path: /etc/iptables/rules.v4
when: do_routing
# TODO: add other dnat ports in above loop?
#- name: add dokuwiki DNAT routing
# iptables:
# table: nat
# chain: PREROUTING
# in_interface: "{{ host_iface }}"
# protocol: tcp
# match: tcp
# source: "{{ host_cidr }}"
# jump: DNAT
# destination_port: "{{ hostvars['dokuwiki']['dnat_dest_port'] }}"
# to_destination: "{{ hostvars['dokuwiki']['internal_ip'] }}"
# become: yes
#
#- name: add freshrss DNAT routing
# iptables:
# table: nat
# chain: PREROUTING
# in_interface: "{{ host_iface }}"
# protocol: tcp
# match: tcp
# source: "{{ host_cidr }}"
# jump: DNAT
# destination_port: "{{ hostvars['freshrss']['dnat_dest_port'] }}"
# to_destination: "{{ hostvars['freshrss']['internal_ip'] }}"
# become: yes

79
roles/lxd_host/tasks/main.yml

@ -1,5 +1,5 @@
--- ---
- import_tasks: lxd_host.yml - name: main lxd_host block
vars: vars:
img_server: https://images.linuxcontainers.org img_server: https://images.linuxcontainers.org
alp_img_alias: alpine/3.13/amd64 alp_img_alias: alpine/3.13/amd64
@ -9,5 +9,80 @@
tmp_pubkey: /tmp/controller_key_rsa.pub tmp_pubkey: /tmp/controller_key_rsa.pub
host_iface: enp2s0 host_iface: enp2s0
host_cidr: '192.168.11.0/24' host_cidr: '192.168.11.0/24'
do_routing: false block:
# TODO: use template for lxd-init --preseed
- name: copy ssh pubkey from controller to lxd host
copy:
src: "{{ lookup('env', 'HOME') + '/.ssh/id_rsa.pub' }}"
dest: "{{ tmp_pubkey }}"
# TODO: might make sense to add a cache redirect for alpine packages
- include_tasks: tasks/container_install.yml
tags: container_install
vars:
container_name: "{{ item }}"
container_sshd_port: "{{ hostvars[item]['ansible_port'] }}"
container_ip: "{{ hostvars[item]['internal_ip'] }}"
tmp_sshd_config: "/tmp/sshd_config_{{ item }}"
with_items: "{{ groups['containers'] }}"
- name: install iptables and iptables-persistent
tags: routing
become: yes
apt:
name: [iptables, iptables-persistent]
state: present
when: "'routing' in ansible_run_tags"
- name: add DNAT rules for containers
tags: routing
iptables:
table: nat
chain: PREROUTING
in_interface: "{{ host_iface }}"
protocol: tcp
match: tcp
source: "{{ host_cidr }}"
jump: DNAT
destination_port: "{{ hostvars[item]['ansible_port'] }}"
to_destination: "{{ hostvars[item]['internal_ip'] }}"
become: yes
with_items: "{{ groups['containers'] }}"
when: "'routing' in ansible_run_tags"
- name: save DNAT rules on lxd host
tags: routing
become: yes
community.general.iptables_state:
table: nat
state: saved
path: /etc/iptables/rules.v4
when: "'routing' in ansible_run_tags"
# TODO: add other dnat ports in above loop?
#- name: add dokuwiki DNAT routing
# iptables:
# table: nat
# chain: PREROUTING
# in_interface: "{{ host_iface }}"
# protocol: tcp
# match: tcp
# source: "{{ host_cidr }}"
# jump: DNAT
# destination_port: "{{ hostvars['dokuwiki']['dnat_dest_port'] }}"
# to_destination: "{{ hostvars['dokuwiki']['internal_ip'] }}"
# become: yes
#
#- name: add freshrss DNAT routing
# iptables:
# table: nat
# chain: PREROUTING
# in_interface: "{{ host_iface }}"
# protocol: tcp
# match: tcp
# source: "{{ host_cidr }}"
# jump: DNAT
# destination_port: "{{ hostvars['freshrss']['dnat_dest_port'] }}"
# to_destination: "{{ hostvars['freshrss']['internal_ip'] }}"
# become: yes

Loading…
Cancel
Save