aboutsummaryrefslogtreecommitdiff
path: root/ansible/roles/lxc-host
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-09-17 23:09:05 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2018-09-17 23:09:05 +0200
commiteac6bfa06de01222ceb33a6865c01fc46d99769f (patch)
tree1515a344dacb54db571df4b25cb14ee06d094e85 /ansible/roles/lxc-host
parent4d6a0f553ae4cbdeec73dffe4aabb3110c0e09c0 (diff)
downloadinfra-eac6bfa06de01222ceb33a6865c01fc46d99769f.tar.gz
infra-eac6bfa06de01222ceb33a6865c01fc46d99769f.tar.bz2
infra-eac6bfa06de01222ceb33a6865c01fc46d99769f.tar.xz
infra-eac6bfa06de01222ceb33a6865c01fc46d99769f.zip
o Lots of VM work.
Diffstat (limited to 'ansible/roles/lxc-host')
-rw-r--r--ansible/roles/lxc-host/tasks/main.yml32
-rw-r--r--ansible/roles/lxc-host/tasks/per-host.yml48
2 files changed, 58 insertions, 22 deletions
diff --git a/ansible/roles/lxc-host/tasks/main.yml b/ansible/roles/lxc-host/tasks/main.yml
index 676e27e..ba511c9 100644
--- a/ansible/roles/lxc-host/tasks/main.yml
+++ b/ansible/roles/lxc-host/tasks/main.yml
@@ -1,23 +1,11 @@
----
-#- debug:
-# msg: key="{{ item.key }}", ipv4="{{ item.value.ipv4 }}"
-# with_dict: "{{ lxc_containers }}"
-- name: Set IPv4 address
- lineinfile:
- path: "/var/lib/lxc/{{ item.key }}/config"
- regexp: "lxc.network.ipv4 *="
- line: "lxc.network.ipv4 = {{ item.value.ipv4.address }}/{{ item.value.ipv4.netmask }}"
- with_dict: "{{ lxc_containers }}"
-- name: Set IPv4 gateway
- lineinfile:
- path: "/var/lib/lxc/{{ item.key }}/config"
- regexp: "lxc.network.ipv4.gateway *="
- line: "lxc.network.ipv4.gateway = {{ item.value.ipv4.gateway }}"
- insertafter: "lxc.network.ipv4 *="
- with_dict: "{{ lxc_containers }}"
-- name: Set logfile
- lineinfile:
- path: "/var/lib/lxc/{{ item.key }}/config"
- regexp: "lxc.logfile *="
- line: "lxc.logfile = /var/lib/lxc/{{ item.key }}/{{ item.key }}.log"
+- name: Remove default network setup packages
+ apt:
+ name: "{{ item }}"
+ install_recommends: no
+ with_items:
+ - python-lxc
+
+- include_tasks: per-host.yml
+ vars:
+ i: "{{ item }}"
with_dict: "{{ lxc_containers }}"
diff --git a/ansible/roles/lxc-host/tasks/per-host.yml b/ansible/roles/lxc-host/tasks/per-host.yml
new file mode 100644
index 0000000..d38267e
--- /dev/null
+++ b/ansible/roles/lxc-host/tasks/per-host.yml
@@ -0,0 +1,48 @@
+- debug:
+ msg: "LXC HOST: {{ i.key }}"
+
+- name: lxc.network.type = veth
+ register: type
+ lineinfile:
+ path: "/var/lib/lxc/{{ i.key }}/config"
+ regexp: "lxc.network.type *="
+ line: "lxc.network.type = veth"
+- name: lxc.network.link = br0
+ register: link
+ lineinfile:
+ path: "/var/lib/lxc/{{ i.key }}/config"
+ regexp: "lxc.network.link *="
+ line: "lxc.network.link = br0"
+- name: Set IPv4 address {{ i.key }}
+ register: ipv4
+ lineinfile:
+ path: "/var/lib/lxc/{{ i.key }}/config"
+ regexp: "lxc.network.ipv4 *="
+ line: "lxc.network.ipv4 = {{ i.value.ipv4.address }}/{{ i.value.ipv4.netmask }}"
+- name: Set IPv4 gateway
+ register: ipv4_gateway
+ lineinfile:
+ path: "/var/lib/lxc/{{ i.key }}/config"
+ regexp: "lxc.network.ipv4.gateway *="
+ line: "lxc.network.ipv4.gateway = {{ i.value.ipv4.gateway }}"
+ insertafter: "lxc.network.ipv4 *="
+- name: Set logfile
+ register: logfile
+ lineinfile:
+ path: "/var/lib/lxc/{{ i.key }}/config"
+ regexp: "lxc.logfile *="
+ line: "lxc.logfile = /var/lib/lxc/{{ i.key }}/{{ i.key }}.log"
+
+#- name: state?
+# debug:
+# msg: "state={{ i.value.state }}"
+#- name: do restart?
+# debug:
+# msg: "DO RESTART: {{ i.key }}"
+# when: i.value.state == 'started'
+
+- name: restart lxc container {{ i.key }}
+ when: i.value.state == 'started' and (type.changed or link.changed or ipv4.changed or logfile.changed)
+ lxc_container:
+ name: "{{ i.key }}"
+ state: restarted