|
|
|
---
|
|
|
|
|
|
|
|
# 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 }}"
|
|
|
|
tags:
|
|
|
|
- raspi
|
|
|
|
|
|
|
|
- name: store MAC address
|
|
|
|
set_fact:
|
|
|
|
my_macaddr: "{{ hostvars[inventory_hostname].ansible_default_ipv4.macaddress }}"
|
|
|
|
tags:
|
|
|
|
- raspi
|
|
|
|
|
|
|
|
- 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: disable ssh login for user pi
|
|
|
|
lineinfile:
|
|
|
|
dest=/etc/ssh/sshd_config
|
|
|
|
line="DenyUsers pi"
|
|
|
|
state=present
|
|
|
|
tags:
|
|
|
|
- raspi
|
|
|
|
|
|
|
|
- name: enable SSH via raspi-config
|
|
|
|
shell: "raspi-config nonint do_ssh 0"
|
|
|
|
when: not raspi_ssh_enabled
|
|
|
|
tags:
|
|
|
|
- raspi
|
|
|
|
|
|
|
|
# Other tasks
|
|
|
|
- include: software.yml
|
|
|
|
- include: users.yml
|
|
|
|
- include: raspi-config.yml
|