8e83016e518fe42d1b04b362351666285565ccc9 — Louis Solofrizzo 7 months ago 0ccd9c4
deploy: Add deployment playbooks

Signed-off-by: Louis Solofrizzo <lsolofrizzo@online.net>
12 files changed, 337 insertions(+), 62 deletions(-)

A deploy/lxd/fast-install-arm.yml
A deploy/lxd/fast-install.yml
A deploy/lxd/install-arm.yml
M deploy/lxd/install.yml
A deploy/lxd/subgid
A deploy/lxd/subuid
M deploy/prd/inventory.yml
D deploy/proxy/create_proxy.sh
D deploy/proxy/proxy.yml
D deploy/proxy/proxy_inventory
D deploy/proxy/socat.service
A deploy/run/restart-lxd-cluster.yml
A deploy/lxd/fast-install-arm.yml => deploy/lxd/fast-install-arm.yml +74 -0
@@ 0,0 1,74 @@
+ - name: LXD Fast Installation
+   hosts: "*pi*"
+   tasks:
+   - name: Install dependencies
+     apt:
+       name:
+         - acl
+         - autoconf
+         - dnsmasq-base
+         - git
+         - libacl1-dev
+         - libcap-dev
+         - liblxc1
+         - lxc-dev
+         - libtool
+         - libuv1-dev
+         - make
+         - pkg-config
+         - rsync
+         - squashfs-tools 
+         - tar
+         - tcl
+         - xz-utils
+         - ebtables
+         - ceph
+       state: present
+ 
+   - name: Install binaries
+     copy:
+       src: "{{ item.src }}"
+       dest: "{{ item.dst }}"
+       mode: +x
+     with_items:
+       - src: arm/lxd
+         dst: /usr/bin/lxd
+       - src: arm/lxc
+         dst: /usr/bin/lxc
+       - src: arm/libco.so.0.1.0
+         dst: /usr/lib/libco.so
+       - src: arm/libraft.so
+         dst: /usr/lib/libraft.so.0
+       - src: arm/libdqlite.so
+         dst: /usr/lib/libdqlite.so.0
+       - src: arm/libsqlite3.so
+         dst: /usr/lib/libsqlite3.so.0
+ 
+   - name: Remove system sqlite
+     file:
+       path: "{{ item }}"
+       state: absent
+     with_items:
+       - /usr/lib/arm-linux-gnueabihf/libsqlite3.so.0.8.6
+       - /usr/lib/arm-linux-gnueabihf/libsqlite3.so.0
+ 
+   - name: Install subuid
+     copy: 
+       src: subuid
+       dest: /etc/subuid
+ 
+   - name: Install subgid
+     copy: 
+       src: subgid
+       dest: /etc/subgid
+ 
+   - name: Install system service
+     copy:
+       src: lxd.service
+       dest: /etc/systemd/system/
+ 
+   - name: Enable system service
+     systemd:
+       name: lxd
+       state: restarted
+       daemon_reload: yes

A deploy/lxd/fast-install.yml => deploy/lxd/fast-install.yml +42 -0
@@ 0,0 1,42 @@
+ - name: LXD Fast Installation
+   hosts: "*intel*"
+   tasks:
+   - name: Install binaries
+     copy:
+       src: "{{ item.src }}"
+       dest: "{{ item.dst }}"
+       mode: +x
+     with_items:
+       - src: intel/lxd
+         dst: /usr/bin/lxd
+       - src: intel/lxc
+         dst: /usr/bin/lxc
+       - src: intel/libco.so.0.1.0
+         dst: /usr/lib/libco.so
+       - src: intel/libraft.so
+         dst: /usr/lib/libraft.so.0
+       - src: intel/libdqlite.so
+         dst: /usr/lib/libdqlite.so.0
+       - src: intel/libsqlite3.so
+         dst: /usr/lib/libsqlite3.so.0
+ 
+   - name: Remove system sqlite
+     file:
+       path: "{{ item }}"
+       state: absent
+     with_items:
+       - /usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6
+       - /usr/lib/x86_64-linux-gnu/libsqlite3.so.0
+ 
+   - name: Install system service
+     copy:
+       src: lxd.service
+       dest: /etc/systemd/system/
+ 
+   - name: Enable system service
+     systemd:
+       name: lxd
+       state: restarted
+       daemon_reload: yes
+ 
+ 

A deploy/lxd/install-arm.yml => deploy/lxd/install-arm.yml +137 -0
@@ 0,0 1,137 @@
+ - name: LXD Installation
+   hosts: "*pi*"
+   environment:
+     GOPATH: "/usr/local/src/"
+   tasks:
+   - name: Install dependencies
+     apt:
+       name:
+         - acl
+         - autoconf
+         - dnsmasq-base
+         - git
+         - libacl1-dev
+         - libcap-dev
+         - liblxc1
+         - lxc-dev
+         - libtool
+         - libuv1-dev
+         - make
+         - pkg-config
+         - rsync
+         - squashfs-tools 
+         - tar
+         - tcl
+         - xz-utils
+         - ebtables
+         - ceph
+       state: present
+ 
+   - name: Get latest golang
+     get_url:
+       url: https://dl.google.com/go/go1.12.5.linux-armv6l.tar.gz
+       dest: /tmp
+ 
+   - name: Unarchive golang
+     unarchive:
+       src: /tmp/go1.12.5.linux-armv6l.tar.gz
+       dest: /usr/local
+       remote_src: yes
+ 
+   - name: Create symbolic link
+     file:
+       src: /usr/local/go/bin/go
+       dest: /usr/bin/go
+       state: link
+ 
+   - name: Cleanup previous installs
+     file:
+       path: "{{ item }}"
+       state: absent
+     with_items:
+       - /usr/local/src/src
+       - /usr/local/src/deps
+ 
+   - name: Get LXD
+     shell: go get -d -v github.com/lxc/lxd/lxd
+ 
+   - name: Get dependencies of LXD
+     shell: make deps
+     args:
+       chdir: /usr/local/src/src/github.com/lxc/lxd
+ 
+   - name: Make LXD
+     shell: git pull && make
+     args:
+       chdir: /usr/local/src/src/github.com/lxc/lxd
+     environment:
+       CGO_CFLAGS: "-I/usr/local/src/deps/sqlite/ -I/usr/local/src/deps/dqlite/include/ -I/usr/local/src/deps/raft/include/ -I/usr/local/src/deps/libco/"
+       CGO_LDFLAGS: "-L/usr/local/src/deps/sqlite/.libs/ -L/usr/local/src/deps/dqlite/.libs/ -L/usr/local/src/deps/raft/.libs -L/usr/local/src/deps/libco/"
+       LD_LIBRARY_PATH: "/usr/local/src/deps/sqlite/.libs/:/usr/local/src/deps/dqlite/.libs/:/usr/local/src/deps/raft/.libs:/usr/local/src/deps/libco/"
+ 
+   - name: Create symlinks
+     file:
+       src: "{{ item.src }}"
+       dest: "{{ item.dest }}"
+       state: link
+     with_items:
+       - src: /usr/local/src/bin/lxd
+         dest: /usr/bin/lxd
+       - src: /usr/local/src/bin/lxc
+         dest: /usr/bin/lxc
+       - src: /usr/local/src/deps/libco/libco.so.0.1.0
+         dest: /usr/lib/libco.so
+       - src: /usr/local/src/deps/raft/.libs/libraft.so
+         dest: /usr/lib/libraft.so.0
+       - src: /usr/local/src/deps/dqlite/.libs/libdqlite.so
+         dest: /usr/lib/libdqlite.so.0
+       - src: /usr/local/src/deps/sqlite/.libs/libsqlite3.so
+         dest: /usr/lib/libsqlite3.so.0
+ 
+   - name: Remove system sqlite
+     file:
+       path: "{{ item }}"
+       state: absent
+     with_items:
+       - /usr/lib/arm-linux-gnueabihf/libsqlite3.so.0.8.6
+       - /usr/lib/arm-linux-gnueabihf/libsqlite3.so.0
+ 
+   - name: Install subuid
+     copy: 
+       src: subuid
+       dest: /etc/subuid
+ 
+   - name: Install subgid
+     copy: 
+       src: subgid
+       dest: /etc/subgid
+ 
+   - name: Install system service
+     copy:
+       src: lxd.service
+       dest: /etc/systemd/system/
+ 
+   - name: Enable system service
+     systemd:
+       name: lxd
+       state: restarted
+       daemon_reload: yes
+ 
+    - name: Get artifacts
+      fetch:
+        src: "{{ item.src }}"
+        dest: "arm/{{ item.dest }}"
+        flat: yes
+      with_items:
+        - src: /usr/local/src/bin/lxd
+          dest: lxd
+        - src: /usr/local/src/bin/lxc
+          dest: lxc
+        - src: /usr/local/src/deps/libco/libco.so.0.1.0
+          dest: libco.so.0.1.0
+        - src: /usr/local/src/deps/raft/.libs/libraft.so
+          dest: libraft.so
+        - src: /usr/local/src/deps/dqlite/.libs/libdqlite.so
+          dest: libdqlite.so
+        - src: /usr/local/src/deps/sqlite/.libs/libsqlite3.so
+          dest: libsqlite3.so

M deploy/lxd/install.yml => deploy/lxd/install.yml +31 -5
@@ 43,13 43,21 @@ dest: /usr/bin/go
        state: link
  
+   - name: Cleanup previous installs
+     file:
+       path: "{{ item }}"
+       state: absent
+     with_items:
+       - /usr/local/src/src
+       - /usr/local/src/deps
+ 
    - name: Get LXD
      shell: go get -d -v github.com/lxc/lxd/lxd
  
- #  - name: Get dependencies of LXD
-     #shell: make deps
-     #args:
-       #chdir: /usr/local/src/src/github.com/lxc/lxd
+   - name: Get dependencies of LXD
+     shell: make deps
+     args:
+       chdir: /usr/local/src/src/github.com/lxc/lxd
  
    - name: Make LXD
      shell: git pull && make


@@ 70,7 78,7 @@ dest: /usr/bin/lxd
        - src: /usr/local/src/bin/lxc
          dest: /usr/bin/lxc
-       - src: /usr/local/src/deps/libco/libco.so
+       - src: /usr/local/src/deps/libco/libco.so.0.1.0
          dest: /usr/lib/libco.so
        - src: /usr/local/src/deps/raft/.libs/libraft.so
          dest: /usr/lib/libraft.so.0


@@ 98,3 106,21 @@ state: restarted
        daemon_reload: yes
  
+    - name: Get artifacts
+      fetch:
+        src: "{{ item.src }}"
+        dest: "intel/{{ item.dest }}"
+        flat: yes
+      with_items:
+        - src: /usr/local/src/bin/lxd
+          dest: lxd
+        - src: /usr/local/src/bin/lxc
+          dest: lxc
+        - src: /usr/local/src/deps/libco/libco.so.0.1.0
+          dest: libco.so.0.1.0
+        - src: /usr/local/src/deps/raft/.libs/libraft.so
+          dest: libraft.so
+        - src: /usr/local/src/deps/dqlite/.libs/libdqlite.so
+          dest: libdqlite.so
+        - src: /usr/local/src/deps/sqlite/.libs/libsqlite3.so
+          dest: libsqlite3.so

A deploy/lxd/subgid => deploy/lxd/subgid +2 -0
@@ 0,0 1,2 @@
+ pi:100000:65536
+ root:1000000:65536

A deploy/lxd/subuid => deploy/lxd/subuid +2 -0
@@ 0,0 1,2 @@
+ pi:100000:65536
+ root:1000000:65536

M deploy/prd/inventory.yml => deploy/prd/inventory.yml +37 -0
@@ 73,6 73,43 @@ ipv4: 10.33.0.18
                  ipmi:
                    ipv4: 10.34.0.18
+           pi:
+             01:
+               net:
+                 cluster:
+                   ipv4: 10.32.0.21
+                 adm:
+                   ipv4: 10.32.0.21
+             02:
+               net:
+                 cluster:
+                   ipv4: 10.32.0.22
+                 adm:
+                   ipv4: 10.32.0.22
+             03:
+               net:
+                 cluster:
+                   ipv4: 10.32.0.23
+                 adm:
+                   ipv4: 10.32.0.23
+             04:
+               net:
+                 cluster:
+                   ipv4: 10.32.0.24
+                 adm:
+                   ipv4: 10.32.0.24
+             05:
+               net:
+                 cluster:
+                   ipv4: 10.32.0.25
+                 adm:
+                   ipv4: 10.32.0.25
+             06:
+               net:
+                 cluster:
+                   ipv4: 10.32.0.26
+                 adm:
+                   ipv4: 10.32.0.26
            monitoring:
              vars:
                net:

D deploy/proxy/create_proxy.sh => deploy/proxy/create_proxy.sh +0 -27
@@ 1,27 0,0 @@-#!/usr/bin/env bash
- 
- DEST="2001:470:c85d:32:216:3eff:fe58:e4a1"
- 
- apt install -yy socat
- 
- for i in {1..1024}; do
- 
-     cat > /etc/systemd/system/socat.tcp.$i.service << EOF
- [Unit]
- Description=Proxy for port $i
- After=network.target
- 
- [Service]
- Type=simple
- User=root
- ExecStart=/usr/bin/socat TCP-LISTEN:$i,fork TCP6:[$DEST]:$i
- Restart=always
- 
- [Install]
- WantedBy=multi-user.target
- EOF
- 
-     systemctl daemon-reload
-     systemctl enable socat.tcp.$i
-     systemctl start socat.tcp.$i
- done

D deploy/proxy/proxy.yml => deploy/proxy/proxy.yml +0 -15
@@ 1,15 0,0 @@-- name: Setup Ipv4 to v6 proxy
-   hosts: "*"
-   tasks:
-   - name: Upload TCP proxy
-     template:
-       src: socat.service
-       dest: /etc/systemd/system/socat.tcp.{{ item }}.service
-     loop: "{{ range(1, 80)|list }}"
- 
-   - name: Start and enable
-     systemd:
-       name: socat.tcp.{{ item }}
-       state: started
-       daemon_reload: yes
-     loop: "{{ range(1, 80)|list }}"

D deploy/proxy/proxy_inventory => deploy/proxy/proxy_inventory +0 -4
@@ 1,4 0,0 @@-5f584750-84e0-4274-8ced-92723f09fd82.pub.cloud.scaleway.com
- 
- [proxy]
- 5f584750-84e0-4274-8ced-92723f09fd82.pub.cloud.scaleway.com src=51.158.102.143 dest=2001:470:c85d:32:216:3eff:fe9c:4209 ansible_user=root

D deploy/proxy/socat.service => deploy/proxy/socat.service +0 -11
@@ 1,11 0,0 @@-[Unit]
- Description=Proxy for port {{ item }}
- After=network.target
- 
- [Service]
- Type=oneshot
- User=root
- ExecStart=/usr/bin/socat TCP-LISTEN:{{ item }},fork TCP6:[{{ dest }}]:{{ item }}
- 
- [Install]
- WantedBy=multi-user.target

A deploy/run/restart-lxd-cluster.yml => deploy/run/restart-lxd-cluster.yml +12 -0
@@ 0,0 1,12 @@
+ - name: LXD Cluster restart
+   hosts: "*intel*:*pi*"
+   tasks:
+   - name: Stop every node
+     systemd:
+       name: lxd
+       state: stopped
+ 
+   - name: Start every node
+     systemd:
+       name: lxd
+       state: started