Skip to content

Commit

Permalink
feat: add deskpi hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
raisedadead committed Sep 26, 2023
1 parent 01b09cc commit 4502828
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ansible/hosts.ini
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions ansible/play--03-setup-hosts.yml
Original file line number Diff line number Diff line change
@@ -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 }}'

0 comments on commit 4502828

Please sign in to comment.