diff --git a/ansible/hosts.ini b/ansible/hosts.ini index 44eb5d2..3913de5 100644 --- a/ansible/hosts.ini +++ b/ansible/hosts.ini @@ -1,5 +1,11 @@ [kendra] kendra.lan.mrugesh.net +[deskpi] +rpi-cm4-01.local +rpi-cm4-04.local +rpi-cm4-05.local +rpi-cm4-06.local + [all:vars] ansible_user=mrugesh diff --git a/ansible/play--03-setup-hosts.yml b/ansible/play--03-setup-hosts.yml new file mode 100644 index 0000000..db39f83 --- /dev/null +++ b/ansible/play--03-setup-hosts.yml @@ -0,0 +1,44 @@ +--- +- name: Update all software on a host + hosts: "{{ variable_host | default('null') }}" + serial: '{{ variable_serial | default(1) }}' + gather_facts: false + become: true + become_user: root + tasks: + - name: Get hostname + ansible.builtin.shell: + cmd: hostname + register: hostname + + - ansible.builtin.debug: + msg: 'Updating {{ hostname.stdout }}' + + - name: Setup Host + ansible.builtin.shell: + cmd: | + # Configure sshd + sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config + sed -i -e '/^PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config + sed -i -e '/^PubkeyAuthentication/s/^.*$/PubkeyAuthentication yes/' /etc/ssh/sshd_config + sed -i -e '$aAllowUsers {{ ansible_user }}' /etc/ssh/sshd_config + # Configure Hostname + sed -i '/preserve_hostname: false/c\preserve_hostname: true' /etc/cloud/cloud.cfg + hostnamectl set-hostname {{ hostname.stdout }}.lan.mrugesh.net + + - name: Reboot the host + ansible.builtin.reboot: + connect_timeout: 5 + reboot_timeout: 300 + pre_reboot_delay: 15 + post_reboot_delay: 15 + test_command: uptime + + - name: Check Hostname + ansible.builtin.shell: + cmd: hostname + register: hostname_check + + - name: Display Hostname + ansible.builtin.debug: + msg: '{{ hostname_check.stdout }}'