diff --git a/metal/group_vars/all.yml b/metal/group_vars/all.yml index 7fbe9f7e..5292cca7 100644 --- a/metal/group_vars/all.yml +++ b/metal/group_vars/all.yml @@ -1,12 +1,5 @@ iso_url: "https://mirrors.nhanhoa.com/centos/8.3.2011/isos/x86_64/CentOS-8.3.2011-x86_64-dvd1.iso" -subnet: "192.168.1.0" -netmask: "255.255.255.0" -gateway: "192.168.1.1" -range_start: "192.168.1.11" -range_end: "192.168.1.99" -pxe_server: "192.168.1.19" -dns: "8.8.8.8" -network_device: "eno1" disk: "sda" +network_interface: "eno1" ssh_public_key: "{{lookup('file', '~/.ssh/id_rsa.pub') }}" diff --git a/metal/hosts.ini b/metal/hosts.ini index 540156e4..a3a8ddcc 100644 --- a/metal/hosts.ini +++ b/metal/hosts.ini @@ -9,4 +9,3 @@ metal3 ansible_host=192.168.1.113 mac='00-23-24-d1-f5-69' [metal:vars] ansible_user=root -subnet=192.168.1.0/24 diff --git a/metal/roles/lxc-config/tasks/main.yml b/metal/roles/lxc-config/tasks/main.yml deleted file mode 100644 index 0ead1b5c..00000000 --- a/metal/roles/lxc-config/tasks/main.yml +++ /dev/null @@ -1,18 +0,0 @@ -- name: Add remote - command: - argv: - - lxc - - remote - - add - - vagrant - - "{{ hostvars[groups['metal'][0]]['ansible_host'] }}" - - --accept-certificate - - --password - - 1 -- name: Change default remote - command: - argv: - - lxc - - remote - - switch - - vagrant diff --git a/metal/roles/lxc-config/templates/env b/metal/roles/lxc-config/templates/env deleted file mode 100644 index 1b16bc66..00000000 --- a/metal/roles/lxc-config/templates/env +++ /dev/null @@ -1,5 +0,0 @@ -ETCDV3_USERNAME={{ etcd_username }} -ETCDV3_PASSWORD={{ etcd_password }} - -LXD_ADDR={{ hostvars[groups['metal'][0]]['ansible_host'] }} -LXD_PASSWORD= {{ lxd_password }} diff --git a/metal/roles/lxd/tasks/main.yml b/metal/roles/lxd/tasks/main.yml index 13d030d2..27889ec3 100644 --- a/metal/roles/lxd/tasks/main.yml +++ b/metal/roles/lxd/tasks/main.yml @@ -1,3 +1,7 @@ +- name: Disable SELinux + selinux: + state: disabled + - name: Install LXD snap: name: lxd @@ -22,3 +26,23 @@ stdin: "{{ lookup('template', 'member.yaml.j2') }}" creates: /var/snap/lxd/common/lxd/server.crt when: inventory_hostname != groups['metal'][0] + +- name: Add remote + command: + argv: + - lxc + - remote + - add + - vagrant + - "{{ hostvars[groups['metal'][0]]['ansible_host'] }}" + - --accept-certificate + - --password + - 1 + +- name: Change default remote + command: + argv: + - lxc + - remote + - switch + - vagrant diff --git a/metal/roles/lxd/templates/leader.yaml.j2 b/metal/roles/lxd/templates/leader.yaml.j2 index 7b0082c3..0887b390 100644 --- a/metal/roles/lxd/templates/leader.yaml.j2 +++ b/metal/roles/lxd/templates/leader.yaml.j2 @@ -4,7 +4,7 @@ config: networks: - config: bridge.mode: fan - fan.underlay_subnet: {{ hostvars[inventory_hostname]['subnet'] }} + fan.underlay_subnet: {{ hostvars[inventory_hostname]['lxd_subnet'] }} description: "" name: lxdfan0 type: "" diff --git a/metal/roles/pxe-server/tasks/main.yml b/metal/roles/pxe-boot/tasks/main.yml similarity index 69% rename from metal/roles/pxe-server/tasks/main.yml rename to metal/roles/pxe-boot/tasks/main.yml index c2c0ec87..f6e8b651 100644 --- a/metal/roles/pxe-server/tasks/main.yml +++ b/metal/roles/pxe-boot/tasks/main.yml @@ -7,10 +7,10 @@ - "{{ role_path }}/build/images" - "{{ role_path }}/build/mnt" -- name: Download ISO - get_url: - url: "{{ iso_url }}" - dest: "{{ role_path }}/build/images/centos8.iso" +# - name: Download ISO +# get_url: +# url: "{{ iso_url }}" +# dest: "{{ role_path }}/build/images/centos8.iso" - name: Mount the ISO mount: @@ -52,3 +52,21 @@ project_src: "{{ role_path }}/build" build: yes delegate_to: localhost + +- name: Unconditionally shut down the machine with all defaults + community.general.shutdown: + delay: 0 + +- name: Wait for the machine to shutdown + wait_for: + timeout: 30 + delegate_to: localhost + +- name: Send magic Wake-on-LAN packet + community.general.wakeonlan: + mac: "{{ hostvars[inventory_hostname]['mac'] }}" + delegate_to: localhost + +- name: Wait for the servers to comes up + wait_for_connection: + timeout: 600 diff --git a/metal/roles/pxe-server/templates/dhcp/Dockerfile b/metal/roles/pxe-boot/templates/dhcp/Dockerfile similarity index 100% rename from metal/roles/pxe-server/templates/dhcp/Dockerfile rename to metal/roles/pxe-boot/templates/dhcp/Dockerfile diff --git a/metal/roles/pxe-server/templates/dhcp/dhcpd.conf.j2 b/metal/roles/pxe-boot/templates/dhcp/dhcpd.conf.j2 similarity index 100% rename from metal/roles/pxe-server/templates/dhcp/dhcpd.conf.j2 rename to metal/roles/pxe-boot/templates/dhcp/dhcpd.conf.j2 diff --git a/metal/roles/pxe-server/templates/docker-compose.yml b/metal/roles/pxe-boot/templates/docker-compose.yml similarity index 100% rename from metal/roles/pxe-server/templates/docker-compose.yml rename to metal/roles/pxe-boot/templates/docker-compose.yml diff --git a/metal/roles/pxe-server/templates/http/Dockerfile b/metal/roles/pxe-boot/templates/http/Dockerfile similarity index 100% rename from metal/roles/pxe-server/templates/http/Dockerfile rename to metal/roles/pxe-boot/templates/http/Dockerfile diff --git a/metal/roles/pxe-server/templates/http/kickstart/centos8.ks.j2 b/metal/roles/pxe-boot/templates/http/kickstart/centos8.ks.j2 similarity index 92% rename from metal/roles/pxe-server/templates/http/kickstart/centos8.ks.j2 rename to metal/roles/pxe-boot/templates/http/kickstart/centos8.ks.j2 index 885bf2d3..63cc9173 100644 --- a/metal/roles/pxe-server/templates/http/kickstart/centos8.ks.j2 +++ b/metal/roles/pxe-boot/templates/http/kickstart/centos8.ks.j2 @@ -1,5 +1,5 @@ %pre --interpreter=/bin/sh -mac=$(ip --brief link show dev {{ network_device }} | tr -s ' ' | cut -d ' ' -f 3 | sed 's/:/-/g') +mac=$(ip --brief link show dev {{ network_interface }} | tr -s ' ' | cut -d ' ' -f 3 | sed 's/:/-/g') curl "http://{{ pxe_server }}/kickstart/network/$mac.ks" > /tmp/network.ks %end diff --git a/metal/roles/pxe-boot/templates/http/kickstart/network/network.ks.j2 b/metal/roles/pxe-boot/templates/http/kickstart/network/network.ks.j2 new file mode 100644 index 00000000..c8bb54d5 --- /dev/null +++ b/metal/roles/pxe-boot/templates/http/kickstart/network/network.ks.j2 @@ -0,0 +1,2 @@ +network --bootproto=static --device={{ network_interface }} --ip={{ hostvars[item]['ansible_host'] }} --gateway={{ gateway }} --nameserver={{ dns }} --netmask={{ netmask }} --ipv6=auto --activate +network --hostname={{ hostvars[item]['inventory_hostname'] }} diff --git a/metal/roles/pxe-server/templates/tftp/Dockerfile b/metal/roles/pxe-boot/templates/tftp/Dockerfile similarity index 100% rename from metal/roles/pxe-server/templates/tftp/Dockerfile rename to metal/roles/pxe-boot/templates/tftp/Dockerfile diff --git a/metal/roles/pxe-server/templates/tftp/tftpboot/grub.cfg.j2 b/metal/roles/pxe-boot/templates/tftp/tftpboot/grub.cfg.j2 similarity index 100% rename from metal/roles/pxe-server/templates/tftp/tftpboot/grub.cfg.j2 rename to metal/roles/pxe-boot/templates/tftp/tftpboot/grub.cfg.j2 diff --git a/metal/roles/pxe-server/templates/http/kickstart/network/network.ks.j2 b/metal/roles/pxe-server/templates/http/kickstart/network/network.ks.j2 deleted file mode 100644 index e0c1ada4..00000000 --- a/metal/roles/pxe-server/templates/http/kickstart/network/network.ks.j2 +++ /dev/null @@ -1,2 +0,0 @@ -network --bootproto=static --device={{ network_device }} --ip={{ hostvars[item]['ansible_host'] }} --gateway={{ gateway }} --nameserver={{ dns }} --netmask={{ netmask }} --ipv6=auto --activate -network --hostname={{ hostvars[item]['inventory_hostname'] }} diff --git a/metal/roles/shutdown/tasks/main.yml b/metal/roles/shutdown/tasks/main.yml deleted file mode 100644 index ab9021f4..00000000 --- a/metal/roles/shutdown/tasks/main.yml +++ /dev/null @@ -1,8 +0,0 @@ -- name: Unconditionally shut down the machine with all defaults - community.general.shutdown: - delay: 0 - -- name: Wait for the machine to shutdown - wait_for: - timeout: 30 - delegate_to: localhost diff --git a/metal/roles/wake/tasks/main.yml b/metal/roles/wake/tasks/main.yml deleted file mode 100644 index ebd8e736..00000000 --- a/metal/roles/wake/tasks/main.yml +++ /dev/null @@ -1,8 +0,0 @@ -- name: Send magic Wake-on-LAN packet - community.general.wakeonlan: - mac: "{{ hostvars[inventory_hostname]['mac'] }}" - delegate_to: localhost - -- name: Wait for the servers to comes up - wait_for_connection: - timeout: 600