diff --git a/ansible/inventory.yaml b/ansible/inventory.yaml new file mode 100644 index 0000000..c9c4e71 --- /dev/null +++ b/ansible/inventory.yaml @@ -0,0 +1,74 @@ +# ip addresses could be acquired from the vms after they're created +cloud-1: + vars: + magic_router_ip: 192.168.100.10 + magic_routes: + - 192.168.101.0/24 + - 192.168.102.0/24 + - 192.168.103.0/24 + ansible_become: true + ansible_user: ubuntu + hosts: + cloud-cluster-1-master-1: + ansible_host: 192.168.100.131 + cloud-cluster-1-worker-1: + ansible_host: 192.168.100.244 + cloud-cluster-1-worker-2: + ansible_host: 192.168.100.244 + + +edge-1: + vars: + magic_router_ip: 192.168.101.10 + magic_routes: + - 192.168.100.0/24 + - 192.168.102.0/24 + - 192.168.103.0/24 + ansible_become: true + ansible_user: ubuntu + hosts: + edge-cluster-1-master-1: + ansible_host: 192.168.101.244 + edge-cluster-1-worker-1: + ansible_host: 192.168.101.244 + edge-cluster-1-worker-2: + ansible_host: 192.168.101.244 + +edge-2: + become: true + user: ubuntu + vars: + magic_router_ip: 192.168.102.10 + magic_routes: + - 192.168.100.0/24 + - 192.168.101.0/24 + - 192.168.103.0/24 + ansible_become: true + ansible_user: ubuntu + hosts: + edge-cluster-2-master-1: + ansible_host: 192.168.102.244 + edge-cluster-2-worker-1: + ansible_host: 192.168.102.244 + edge-cluster-2-worker-2: + ansible_host: 192.168.102.244 + +site-1: + vars: + magic_router_ip: 192.168.103.10 + magic_routes: + - 192.168.100.0/24 + - 192.168.101.0/24 + - 192.168.102.0/24 + ansible_become: true + ansible_user: ubuntu + hosts: + site-emulator-1: + ansible_host: 192.168.103.244 + +all: + children: + cloud-1: + edge-1: + edge-2: + site-1: diff --git a/ansible/prepare.yaml b/ansible/prepare.yaml new file mode 100644 index 0000000..1a0ed86 --- /dev/null +++ b/ansible/prepare.yaml @@ -0,0 +1,28 @@ +- name: "prepare vms for ultrabirb-cluster" + hosts: all + handlers: + - name: "netplan apply" + block: + - name: "run netplan apply" + command: netplan apply + async: 45 + poll: 0 + + - name: "reset connections" + meta: reset_connection + + - name: clear errors + meta: clear_host_errors + + tasks: + - name: "disable cloudinit" + import_tasks: tasks/disable-cloudinit.yaml + + - name: "remove snap" + import_tasks: tasks/remove-snap.yaml + + - name: "clean motd" + import_tasks: tasks/clean-motd.yaml + + - name: "setup static route" + import_tasks: tasks/setup-static-route.yaml \ No newline at end of file diff --git a/ansible/tasks/apt.yaml b/ansible/tasks/apt.yaml new file mode 100644 index 0000000..32d9fcb --- /dev/null +++ b/ansible/tasks/apt.yaml @@ -0,0 +1,28 @@ +- name: "Remove ubuntu stuff" + apt: + state: absent + name: ubutu-server + autoremove: yes + +- name: "Install my favourite applications" + apt: + state: present + name: + - tmux + - htop + - dnsutils + - needrestart + - curl + - wget + - netcat-openbsd + - tree + - net-tools + - nano + - psmisc + - python3 + - python3-venv + - strace + - ifstat + - tcpdump + - xxd + - git \ No newline at end of file diff --git a/ansible/tasks/clean-motd.yaml b/ansible/tasks/clean-motd.yaml new file mode 100644 index 0000000..09df8bd --- /dev/null +++ b/ansible/tasks/clean-motd.yaml @@ -0,0 +1,13 @@ +# This changes permissions so update motd can not read it +- name: clean motd + file: + state: file + path: /etc/update-motd.d/{{ item }} + owner: root + group: root + mode: "0000" + with_items: + - 10-help-text + - 50-landscape-sysinfo + - 50-motd-news + - 91-release-upgrade \ No newline at end of file diff --git a/ansible/tasks/disable-cloudinit.yaml b/ansible/tasks/disable-cloudinit.yaml new file mode 100644 index 0000000..f08e3e6 --- /dev/null +++ b/ansible/tasks/disable-cloudinit.yaml @@ -0,0 +1,12 @@ +- name: disable cloudinit + copy: + content: "" + dest: /etc/cloud/cloud-init.disabled + force: no + +- name: disable network autoconfig + copy: + content: "network: {config: disabled}" + dest: /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg + force: no + diff --git a/ansible/tasks/remove-snap.yaml b/ansible/tasks/remove-snap.yaml new file mode 100644 index 0000000..5fbd049 --- /dev/null +++ b/ansible/tasks/remove-snap.yaml @@ -0,0 +1,17 @@ +- name: Remove snapd from Ubuntu + apt: + name: snapd + state: absent + purge: yes + when: ansible_distribution == "Ubuntu" + +- name: Remove snapd-related directories + file: + path: "{{ item }}" + state: absent + with_items: + - /snap + - /var/snap + - /var/lib/snapd + - "/home/{{ ansible_user }}/snap" + when: ansible_distribution == "Ubuntu" \ No newline at end of file diff --git a/ansible/tasks/setup-static-route.yaml b/ansible/tasks/setup-static-route.yaml new file mode 100644 index 0000000..4cbeb81 --- /dev/null +++ b/ansible/tasks/setup-static-route.yaml @@ -0,0 +1,10 @@ +- name: "remove cloudinit config" + file: + path: /etc/netplan/50-cloud-init.yaml + state: absent + +- name: "install static config" + template: + src: templates/netplan.yaml + dest: /etc/netplan/00-static.yaml + notify: "netplan apply" \ No newline at end of file diff --git a/ansible/templates/netplan.yaml b/ansible/templates/netplan.yaml new file mode 100644 index 0000000..51e2e6a --- /dev/null +++ b/ansible/templates/netplan.yaml @@ -0,0 +1,15 @@ +# {{ansible_managed}} +version: 2 +network: + ethernets: + {{ansible_default_ipv4.interface}}: + dhcp4: false + dhcp6: false + gateway4: {{ ansible_default_ipv4.gateway }} + addresses: + - "{{ ansible_host }}/24" + routes: +{% for item in magic_routes %} + - to: {{ item }} + via: {{ magic_router_ip }} +{% endfor %} \ No newline at end of file