From 815eaf938472c59d34074583f365a482f06fc8db Mon Sep 17 00:00:00 2001 From: "Glenn K. Lockwood" Date: Sun, 28 Oct 2018 14:13:15 -0700 Subject: [PATCH] enable setting of most raspi-config options --- roles/common/tasks/linux-facts.yml | 7 +++ roles/common/tasks/main.yml | 31 +++++++++---- roles/common/tasks/raspi-config.yml | 70 +++++++++++++++++++++++++---- roles/common/vars/main.yml | 3 ++ 4 files changed, 95 insertions(+), 16 deletions(-) diff --git a/roles/common/tasks/linux-facts.yml b/roles/common/tasks/linux-facts.yml index 71754e0..59c3602 100644 --- a/roles/common/tasks/linux-facts.yml +++ b/roles/common/tasks/linux-facts.yml @@ -11,8 +11,15 @@ changed_when: False check_mode: no +- name: get x keyboard layout + shell: "localectl | awk '/X11 Layout/ {print $3}'" + register: linux_xkblayout + changed_when: False + check_mode: no + - name: set linux-config facts set_fact: linux_tz: "{{ linux_tz.stdout }}" linux_locale: "{{ linux_locale.stdout }}" + linux_xkblayout: "{{ linux_xkblayout }}" check_mode: no diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 5e83b60..7d08d84 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -17,17 +17,22 @@ tags: - raspi +- name: store system configuration + set_fact: + myconfig: "{{ macaddrs[my_macaddr] }}" + tags: + - raspi + - name: set hostname - shell: "raspi-config nonint do_hostname {{ macaddrs[my_macaddr].hostname }}" - when: raspi_hostname != macaddrs[my_macaddr].hostname + shell: "raspi-config nonint do_hostname {{ myconfig.hostname }}" + when: raspi_hostname != myconfig.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 }}" + line="{{ ansible_default_ipv4.address }}{{'\t'}}{{ myconfig.hostname }}.{{ myconfig.domain }}{{'\t'}}{{ myconfig.hostname }}" state=present - when: my_macaddr in macaddrs - name: get rid of default 127.0.1.1 binding lineinfile: @@ -37,13 +42,23 @@ # Set timezone - name: set timezone - shell: "timedatectl set-timezone {{ macaddrs[my_macaddr].timezone }}" - when: linux_tz != macaddrs[my_macaddr].timezone + command: "timedatectl set-timezone {{ myconfig.timezone }}" + when: linux_tz != myconfig.timezone # Set locale - name: set locale - shell: "raspi-config nonint do_change_locale {{ macaddrs[my_macaddr].locale }}" - when: linux_locale != macaddrs[my_macaddr].locale + command: "raspi-config nonint do_change_locale {{ myconfig.locale }}" + when: "'locale' in myconfig and linux_locale != myconfig.locale" + +# Set X keyboard layout +- name: set X11 keyboard layout + command: "raspi-config nonint do_configure_keyboard {{ myconfig.xkblayout }}" + when: "'xkblayout' in myconfig and myconfig.xkblayout != linux_xkblayout" + +# Set wifi country +- name: set wifi country + command: "raspiconfig nonint do_wifi_country {{ myconfig.wifi_country }}" + when: "'wifi_country' in myconfig and myconfig.wifi_country != raspi_wifi_country" # Enable sshd - name: disable ssh login for user pi diff --git a/roles/common/tasks/raspi-config.yml b/roles/common/tasks/raspi-config.yml index 185d9d5..dfde754 100644 --- a/roles/common/tasks/raspi-config.yml +++ b/roles/common/tasks/raspi-config.yml @@ -3,37 +3,91 @@ # Handle boot and autologin settings - name: enable cli only command: "raspi-config nonint do_boot_behaviour B1" - when: not macaddrs[my_macaddr].enable_gui and not macaddrs[my_macaddr].enable_autologin and (raspi_gui_enabled or raspi_autologin_enabled) + when: not myconfig.enable_gui and not myconfig.enable_autologin and (raspi_gui_enabled or raspi_autologin_enabled) tags: - raspi - name: enable cli with autologin command: "raspi-config nonint do_boot_behaviour B2" - when: not macaddrs[my_macaddr].enable_gui and macaddrs[my_macaddr].enable_autologin and (raspi_gui_enabled or not raspi_autologin_enabled) + when: not myconfig.enable_gui and myconfig.enable_autologin and (raspi_gui_enabled or not raspi_autologin_enabled) tags: - raspi - name: enable desktop gui command: "raspi-config nonint do_boot_behaviour B3" - when: macaddrs[my_macaddr].enable_gui and not macaddrs[my_macaddr].enable_autologin and (not raspi_gui_enabled or raspi_autologin_enabled) + when: myconfig.enable_gui and not myconfig.enable_autologin and (not raspi_gui_enabled or raspi_autologin_enabled) tags: - raspi - name: enable desktop gui with autologin command: "raspi-config nonint do_boot_behaviour B4" - when: macaddrs[my_macaddr].enable_gui and macaddrs[my_macaddr].enable_autologin and (not raspi_gui_enabled or raspi_autologin_enabled) + when: myconfig.enable_gui and myconfig.enable_autologin and (not raspi_gui_enabled or raspi_autologin_enabled) tags: - raspi - name: set bootwait option - command: "raspi-config nonint do_boot_wait {{ 1 if not macaddrs[my_macaddr].enable_bootwait else 0 }}" - when: "'enable_bootwait' in macaddrs[my_macaddr] and macaddrs[my_macaddr].enable_bootwait != raspi_bootwait_enabled" + command: "raspi-config nonint do_boot_wait {{ 0 if myconfig.enable_bootwait else 1 }}" + when: "'enable_bootwait' in myconfig and myconfig.enable_bootwait != raspi_bootwait_enabled" tags: - raspi - name: set boot splash option - command: "raspi-config nonint do_boot_splash {{ 1 if not macaddrs[my_macaddr].enable_bootsplash else 0 }}" - when: "'enable_bootsplash' in macaddrs[my_macaddr] and macaddrs[my_macaddr].enable_bootsplash != raspi_bootsplash_enabled" + command: "raspi-config nonint do_boot_splash {{ 0 if myconfig.enable_bootsplash else 1 }}" + when: "'enable_bootsplash' in myconfig and myconfig.enable_bootsplash != raspi_bootsplash_enabled" + tags: + - raspi + +- name: enable/disable camera + command: "raspi-config nonint do_camera {{ 0 if myconfig.enable_camera else 1 }}" + when: "'enable_camera' in myconfig and myconfig.enable_camera != raspi_camera_enabled" + tags: + - raspi + +- name: enable/disable VNC server + command: "raspi-config nonint do_vnc {{ 0 if myconfig.enable_vnc else 1 }}" + when: "'enable_vnc' in myconfig and myconfig.enable_vnc != raspi_vnc_enabled" + tags: + - raspi + +- name: enable/disable SPI + command: "raspi-config nonint do_spi {{ 0 if myconfig.enable_spi else 1 }}" + when: "'enable_spi' in myconfig and myconfig.enable_spi != raspi_spi_enabled" + tags: + - raspi + +- name: enable/disable I2C + command: "raspi-config nonint do_i2c {{ 0 if myconfig.enable_i2c else 1 }}" + when: "'enable_i2c' in myconfig and myconfig.enable_i2c != raspi_i2c_enabled" + tags: + - raspi + +- name: enable/disable serial + command: "raspi-config nonint do_serial {{ 0 if myconfig.enable_serial else 1 }}" + when: "'enable_serial' in myconfig and myconfig.enable_serial != raspi_serial_enabled" + tags: + - raspi + +- name: enable/disable hardware serial + command: "raspi-config nonint do_serial_hw {{ 0 if myconfig.enable_serial_hw else 1 }}" + when: "'enable_serial_hw' in myconfig and myconfig.enable_serial_hw != raspi_serial_hw_enabled" + tags: + - raspi + +- name: enable/disable onewire + command: "raspi-config nonint do_onewire {{ 0 if myconfig.enable_onewire else 1 }}" + when: "'enable_onewire' in myconfig and myconfig.enable_onewire != raspi_onewire_enabled" + tags: + - raspi + +- name: enable/disable remote GPIO + command: "raspi-config nonint do_rgpio {{ 0 if myconfig.enable_rgpio else 1 }}" + when: "'enable_rgpio' in myconfig and myconfig.enable_rgpio != raspi_rgpio_enabled" + tags: + - raspi + +- name: enable/disable HDMI overscan + command: "raspi-config nonint do_overscan {{ 0 if myconfig.enable_overscan else 1 }}" + when: "'enable_overscan' in myconfig and myconfig.enable_overscan != raspi_overscan_enabled" tags: - raspi diff --git a/roles/common/vars/main.yml b/roles/common/vars/main.yml index 34eddfb..7c3d1eb 100644 --- a/roles/common/vars/main.yml +++ b/roles/common/vars/main.yml @@ -5,6 +5,8 @@ macaddrs: domain: "local" locale: "en_US.UTF-8" timezone: "America/Los_Angeles" + xkblayout: "us" + wifi_country: "US" enable_gui: True enable_autologin: False enable_bootwait: False @@ -22,6 +24,7 @@ macaddrs: domain: "local" locale: "en_US.UTF-8" timezone: "America/Los_Angeles" + xkblayout: "us" enable_gui: False enable_autologin: False enable_bootwait: True