Skip to content

Commit 83e4722

Browse files
committed
New variable boot_config_lines, version 1.1
1 parent e7e7ece commit 83e4722

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

README.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Ansible role: rpi-boot-config
22
=============================
33

4-
Minimal role to manage config entries in a Raspberry PI [boot config](http://www.raspberrypi.org/documentation/configuration/config-txt.md). After changing the boot config, it will restart the raspberry pi and wait for it to come back. This requires that the *ansible_host* is set correctly in the inventory:
4+
Minimal role to manage config entries in a Raspberry PI [boot config](http://www.raspberrypi.org/documentation/configuration/config-txt.md). After changing the boot config, it will restart the raspberry pi and wait for it to come back. This requires either the `inventory_hostname` is resolvable or that the `ansible_host` is set correctly in the inventory:
55

66
[all]
77
raspberry ansible_host=192.168.1.101
@@ -17,12 +17,27 @@ Role Variables
1717

1818
Available variables are listed below, along with default values (see defaults/main.yml):
1919

20-
boot_config: {}
20+
**boot\_config\_lines**, optional
2121

22-
This is the only variable for this role right now. If used, it has to be a dictionary with key value pairs, each of which will be set in the boot config. Example:
22+
List of verbatim config lines to be put into `/boot/config.txt` (no assertions about uniqueness are made). Example:
23+
24+
```
25+
boot_config_lines:
26+
- "gpu_mem=196"
27+
- "dtoverlay=pi3-disable-wifi"
28+
- "dtoverlay=pi3-disable-bt"
29+
```
30+
31+
32+
**boot\_config**, optional
33+
34+
Dictionary where every key translates to a unique setting in `/boot/config.txt`. Example:
35+
36+
```
37+
boot_config:
38+
gpu_mem: '196'
39+
```
2340

24-
boot_config:
25-
gpu_mem: 196
2641

2742
Dependencies
2843
------------
@@ -34,7 +49,17 @@ Example Playbook
3449

3550
- hosts: raspberrypis
3651
roles:
37-
- { role: rpi_boot_config, boot_config: {'gpu_mem': '196'} }
52+
- { role: rpi_boot_config, boot_config_lines: ['gpu_mem=196'] }
53+
54+
Changelog
55+
---------
56+
57+
### 1.1
58+
* added new, optional variable `boot_config_lines`
59+
60+
### 1.0
61+
* initial release
62+
3863

3964
License
4065
-------

defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
22
# defaults for rpi-boot-config
3+
34
boot_config: {}
45
# gpu_mem: 64
6+
7+
boot_config_lines: []
8+
# - "gpu_mem=64"

tasks/main.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
---
22
# tasks file for rpi-boot-config
3-
- name: "adjust /boot/config.txt"
4-
lineinfile: line='{{ item.key }}={{ item.value }}'
5-
dest=/boot/config.txt
6-
regexp="^{{ item.key }}="
3+
- name: "adjust /boot/config.txt based on boot_config"
4+
lineinfile:
5+
line: '{{ item.key }}={{ item.value }}'
6+
dest: /boot/config.txt
7+
regexp: "^{{ item.key }}="
78
with_dict: '{{ boot_config }}'
89
register: _boot_config
910

11+
- name: "adjust /boot/config.txt based on boot_config_lines"
12+
lineinfile:
13+
line: '{{ item }}'
14+
dest: /boot/config.txt
15+
regexp: "^{{ item }}"
16+
with_items: '{{ boot_config_lines }}'
17+
register: _boot_config_lines
18+
1019
- name: restart machine
1120
shell: sleep 2 && shutdown -r now "/boot/config.txt config changed"
1221
async: 1
1322
poll: 0
1423
ignore_errors: true
15-
when: _boot_config.changed
24+
when: _boot_config.changed or _boot_config_lines.changed
25+
1626

1727
- name: waiting for machine to come back
18-
local_action: wait_for port=22 host="{{ ansible_host }}" delay=20 timeout=120
28+
local_action: wait_for port=22 host="{{ ansible_host|default(inventory_hostname) }}" delay=20 timeout=120
1929
become: false
20-
when: _boot_config.changed
30+
when: _boot_config.changed or _boot_config_lines.changed

0 commit comments

Comments
 (0)