12 changed files with 131 additions and 168 deletions
@ -0,0 +1,16 @@
|
||||
--- |
||||
- hosts: lxd_host |
||||
roles: |
||||
- lxd_host |
||||
|
||||
#- hosts: containers |
||||
# roles: |
||||
# - webserver |
||||
# |
||||
#- hosts: freshrss |
||||
# roles: |
||||
# - freshrss |
||||
# |
||||
#- hosts: dokuwiki |
||||
# roles: |
||||
# - dokuwiki |
||||
@ -1,101 +0,0 @@
|
||||
--- |
||||
- name: top level play for lxd server provisioning |
||||
hosts: lxd_host |
||||
tags: install_lxd |
||||
tasks: |
||||
- name: include variables |
||||
include_vars: |
||||
file: site_vars.yml |
||||
|
||||
# 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_common.yml |
||||
vars: |
||||
container_name: "{{ item.key }}" |
||||
container_sshd_port: "{{ item.value.sshd_port }}" |
||||
container_ip: "{{ item.value.ip }}" |
||||
tmp_sshd_config: "/tmp/sshd_config_{{ item.key }}" |
||||
with_items: "{{ containers | dict2items }}" |
||||
|
||||
|
||||
# |
||||
# container specific playbooks |
||||
# |
||||
|
||||
- import_playbook: tasks/dokuwiki.yml |
||||
|
||||
# |
||||
# DNAT routing |
||||
# |
||||
|
||||
# NOTE: do host routing last so we can fail on no sudo pass |
||||
|
||||
- name: add DNAT rules for ssh to containers |
||||
hosts: lxd_host |
||||
tags: dnat_route |
||||
tasks: |
||||
- include_vars: |
||||
file: site_vars.yml |
||||
|
||||
- name: install iptables and iptables-persistent |
||||
become: yes |
||||
apt: |
||||
name: [iptables, iptables-persistent] |
||||
state: present |
||||
|
||||
- name: add rules on containers |
||||
iptables: |
||||
table: nat |
||||
chain: PREROUTING |
||||
in_interface: "{{ host_iface }}" |
||||
protocol: tcp |
||||
match: tcp |
||||
source: "{{ host_cidr }}" |
||||
jump: DNAT |
||||
destination_port: "{{ item.value.sshd_port }}" |
||||
to_destination: "{{ item.value.ip }}" |
||||
become: yes |
||||
with_items: "{{ containers | dict2items }}" |
||||
|
||||
- name: save DNAT rules on lxd host |
||||
become: yes |
||||
community.general.iptables_state: |
||||
table: nat |
||||
state: saved |
||||
path: /etc/iptables/rules.v4 |
||||
|
||||
- name: add DNAT rules for individual containers |
||||
hosts: lxd_host |
||||
tags: dnat_route_2 |
||||
tasks: |
||||
- include_vars: |
||||
file: site_vars.yml |
||||
|
||||
- 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 |
||||
|
||||
- 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 |
||||
@ -1,9 +0,0 @@
|
||||
--- |
||||
- hosts: lxd_containers |
||||
roles: |
||||
- webserver |
||||
|
||||
- hosts: freshrss |
||||
tags: freshrss |
||||
roles: |
||||
- freshrss |
||||
@ -0,0 +1,74 @@
|
||||
--- |
||||
# 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: containers |
||||
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 |
||||
|
||||
- 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'] }}" |
||||
|
||||
- name: save DNAT rules on lxd host |
||||
tags: routing |
||||
become: yes |
||||
community.general.iptables_state: |
||||
table: nat |
||||
state: saved |
||||
path: /etc/iptables/rules.v4 |
||||
|
||||
# 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 |
||||
|
||||
@ -0,0 +1,12 @@
|
||||
--- |
||||
- import_tasks: lxd_host.yml |
||||
vars: |
||||
img_server: https://images.linuxcontainers.org |
||||
alp_img_alias: alpine/3.13/amd64 |
||||
lxc_cmd: /snap/bin/lxc |
||||
lxd_subnet_pfx: 10.98.46 |
||||
lxd_bridge: lxdbr0 |
||||
tmp_pubkey: /tmp/controller_key_rsa.pub |
||||
host_iface: enp2s0 |
||||
host_cidr: '192.168.11.0/24' |
||||
|
||||
@ -1,32 +0,0 @@
|
||||
|
||||
var.basedir = "/var/www/localhost" |
||||
var.logdir = "/var/log/lighttpd" |
||||
var.statedir = "/var/lib/lighttpd" |
||||
|
||||
server.modules = ( |
||||
"mod_access", |
||||
"mod_accesslog", |
||||
"mod_rewrite" |
||||
) |
||||
|
||||
include "mime-types.conf" |
||||
include "mod_fastcgi.conf" |
||||
|
||||
server.username = "lighttpd" |
||||
server.groupname = "lighttpd" |
||||
server.document-root = var.basedir + "/htdocs" |
||||
server.pid-file = "/run/lighttpd.pid" |
||||
server.errorlog = var.logdir + "/error.log" |
||||
server.indexfiles = ("index.php", "index.html", "index.htm", "default.htm") |
||||
server.follow-symlink = "enable" |
||||
|
||||
static-file.exclude-extensions = (".php", ".pl", ".cgi", ".fcgi") |
||||
|
||||
accesslog.filename = var.logdir + "/access.log" |
||||
|
||||
url.access-deny = ("~", ".inc") |
||||
|
||||
$HTTP["url"] =~ "^/dokuwiki/(data|conf|bin|inc|vendor)/+." { |
||||
url.access-deny = ("") |
||||
} |
||||
|
||||
@ -1,22 +0,0 @@
|
||||
--- |
||||
img_server: https://images.linuxcontainers.org |
||||
alp_img_alias: alpine/3.13/amd64 |
||||
lxc_cmd: /snap/bin/lxc |
||||
lxd_subnet_pfx: 10.98.46 |
||||
lxd_bridge: lxdbr0 |
||||
tmp_pubkey: /tmp/controller_key_rsa.pub |
||||
host_iface: enp2s0 |
||||
host_cidr: '192.168.11.0/24' |
||||
|
||||
# TODO: move this info to inventory file |
||||
containers: |
||||
#- transmission |
||||
dokuwiki: |
||||
ip: "{{ lxd_subnet_pfx }}.100" |
||||
sshd_port: 2225 |
||||
freshrss: |
||||
ip: "{{ lxd_subnet_pfx }}.101" |
||||
sshd_port: 2226 |
||||
gitweb: |
||||
ip: "{{ lxd_subnet_pfx }}.102" |
||||
sshd_port: 2227 |
||||
Loading…
Reference in new issue