--- # Gather facts specific to the Raspberry Pi platform - include: raspi-facts.yml - include: linux-facts.yml # Basic hostname setup - name: Get MAC address debug: msg: "{{ hostvars[inventory_hostname].ansible_default_ipv4.macaddress }}" - name: store MAC address set_fact: my_macaddr: "{{ hostvars[inventory_hostname].ansible_default_ipv4.macaddress }}" - name: print configured hostname debug: msg: "raspi-config hostname: {{ raspi_hostname }} vs. intended: {{ macaddrs[my_macaddr].hostname }}" - name: set hostname shell: "raspi-config nonint do_hostname {{ macaddrs[my_macaddr].hostname }}" when: raspi_hostname != macaddrs[my_macaddr].hostname - name: update /etc/hosts with new hostname lineinfile: dest=/etc/hosts regexp="^{{ ansible_default_ipv4.address }}" line="{{ ansible_default_ipv4.address }}{{'\t'}}{{ macaddrs[my_macaddr].hostname }}.{{ macaddrs[my_macaddr].domain }}{{'\t'}}{{ macaddrs[my_macaddr].hostname }}" state=present when: my_macaddr in macaddrs - name: get rid of default 127.0.1.1 binding lineinfile: dest=/etc/hosts regexp="^127.0.1.1" state=absent # Set timezone - name: set timezone shell: "timedatectl set-timezone {{ macaddrs[my_macaddr].timezone }}" when: linux_tz != macaddrs[my_macaddr].timezone # Set locale - name: set locale shell: "raspi-config nonint do_change_locale {{ macaddrs[my_macaddr].locale }}" when: linux_locale != macaddrs[my_macaddr].locale # Enable sshd - name: forbid login via 'pi' user via ssh lineinfile: dest=/etc/ssh/sshd_config line="DenyUsers pi" state=present - name: enable SSH shell: "raspi-config nonint do_ssh 0" when: raspi_ssh_disabled != '0' # Other tasks - include: software.yml - include: users.yml - include: hardware.yml