fpiesche.raspi_setup

ansible-role-raspi-setup

一个 Ansible 角色,用于在一组 Raspberry Pi 主机上进行基本设置,适用于无头机器。

在新安装的 Raspberry Pi OS 上运行此角色时,仅启用 SSH(在首次启动前在 SD 卡的 boot 分区添加一个名为 ssh 的空文件!),可以使用此角色来:

  • hostname 设置为 Ansible 清单中的主机名或变量 local_hostname 中给出的主机名
  • 从变量 config_settings 中设置不同 Raspberry Pi 的 config.txt 中的各种选项
  • 将授权的 SSH 密钥添加到 pi 用户,以实现无密码登录,这些密钥来自变量 authorized_keys
  • 从变量 pi_password 中更改 pi 用户的默认密码

要跳过任何步骤,只需不设置相关变量即可。

我建议将此与 dev-sec.ssh-hardening 结合使用,该角色将禁止 SSH 密码登录以提高安全性,并对 SSHD 的默认设置进行一系列其他安全性改进。

此外,如果有需要,可以使用 geerlingguy.swap 来设置交换文件!

示例剧本

主剧本 playbook.yml

- hosts: raspis
  roles:
    # 该角色将自动为给定的密钥设置无密码 SSH
    # 并根据主机清单定制任何传入的 config.txt 设置。
    - role: fpiesche.raspi_setup
      vars:
        # 这些值将作为所有 Raspberry Pi 的默认值,但可以
        # 在每个主机基础上进行覆盖。            
        authorized_keys: ["{{ lookup('file', lookup('env', 'HOME') + '/.ssh/id_rsa.pub') }}",
                          "/home/otheruser/.ssh/id_rsa.pub",
                          "ssh-rsa ..."]
        # `pi_password` 变量必须是哈希密码。
        pi_password: "{{ raspberry | password_hash('sha512') }}"

    # 推荐:该角色将锁定 SSH 访问以禁止密码登录
    # 并对默认的 SSH 设置进行其他安全改进。
    # https://github.com/dev-sec/ansible-ssh-hardening
    - role: dev-sec.ssh-hardening
      become: yes
    
    # 可选:使用 `swap_megabytes` 主机变量设置交换文件
    # https://github.com/geerlingguy/ansible-role-swap
    - role: geerlingguy.swap
      become: yes

清单 hosts.yml

这是我为不同版本的 Pi 设置的 Docker 集群的 hosts.yml 的一部分:

---
all:
  children:
    raspis:
      vars:
        ansible_python_interpreter: /usr/bin/python3
        ansible_user: pi
        ansible_password: raspberry
      hosts:
        pi-1-a.local:
          # 为这个 Pi 的 `pi` 用户设置不同的密码
          pi_password: "{{ pi1-password | password_hash('sha512') }}"
          # config_settings 部分中的任何内容将自动设置
          # 在这个 Pi 的 config.txt 中,并在之后重启系统。
          config_settings:
            - name: "gpu_mem"
              value: 16
            # 从
            # https://haydenjames.io/raspberry-pi-safe-overclocking-settings/ 获取的 Raspberry Pi 1 超频设置
            - name: "arm_freq"
              value: 1000
            - name: "sdram_freq"
              value: 500
            - name: "core_freq"
              value: 500
            - name: "over_voltage"
              value: 6
            - name: "temp_limit"
              value: 75
          # 这是 Jeff Geerling 的 `geerlingguy.swap` 角色用来设置 1GB 交换文件的。
          # https://github.com/geerlingguy/ansible-role-swap
          swap_file_size_mb: 1024

        pi-2.local:
          pi_password: "{{ pi2-password | password_hash('sha512') }}"
          local_hostname: that-other-one
          config_settings:
            - name: "gpu_mem"
              value: 16
            # 从
            # https://wiki.debian.org/RaspberryPi#Overclocking_Pi_2 获取的 Raspberry Pi 2 超频设置
            - name: "arm_freq"
              value: 1000
            - name: "core_freq"
              value: 500
            - name: "sdram_freq"
              value: 400
            - name: "over_voltage"
              value: 0
            - name: "over_voltage_sdram_p"
              value: 0
            - name: "over_voltage_sdram_i"
              value: 0
            - name: "over_voltage_sdram_c"
              value: 0
            - name: "temp_limit"
              value: 75
          swap_file_size_mb: 1024
关于项目

Perform basic setup for headless use on newly deployed Raspberry Pi OS installations

安装
ansible-galaxy install fpiesche.raspi_setup
许可证
Unknown
下载
382
拥有者