First commit

This commit is contained in:
Yorick Barbanneau 2022-11-30 09:40:47 +01:00
commit ed405fe273
4 changed files with 104 additions and 0 deletions

40
README.md Normal file
View file

@ -0,0 +1,40 @@
Swaylock Ansible Role
---------------------
Install and configure [swaylock](https://github.com/swaywm/swaylock)
## Variables
You can define 3 variables for this role, all are optionnals.
`swaylock_flags` list options which do not need valus like `daemonize`:
```yaml
---
swaylock_flags:
- ignore-empty-password
- show-failed-attempts
- daemonize
```
`swaylock_options` list key-value type options like `image` or all colors
related stuff:
```yaml
swaylock_options:
image: '~/documents/ressources/wallpapers/psychonauts.jpg'
```
You can check *Swaylock* manual pages (`man swaylock`) for all options.
The last variable, `swaylock_keybinding` list *Swaylock* related keybinding for
*Sway*. Check my [Sway Ansible role](https://git.epha.se/ephase/ansible-sway)
for managing this variable.
```yaml
swaylock_keybindings:
- mode: normal
bindings:
- bindsym: '$mod+alt+l'
action: 'exec swaylock'
```

39
tasks/main.yml Normal file
View file

@ -0,0 +1,39 @@
---
- name: Install Swaylock package
ansible.builtin.package:
name: swaylock
state: present
become: true
- name: Create Swaylock config dirs
ansible.builtin.file:
path: '{{ ansible_user_dir ~ "/.config/swaylock" }}'
state: directory
mode: 0750
owner: '{{ ansible_user_uid }}'
group: '{{ ansible_user_gid }}'
- name: Render templates for Swaylock config file
ansible.builtin.template:
src: config.j2
dest: '{{ ansible_user_dir}}/.config/swaylock/config'
owner: '{{ ansible_user_uid }}'
group: '{{ ansible_user_gid }}'
lstrip_blocks: yes
trim_blocks: yes
mode: 0640
- name: Render Swaylock keybinding for sway config file
ansible.builtin.template:
src: '{{ item }}.config.j2'
dest: '{{ ansible_user_dir ~ "/.config/sway/conf.d/" ~ item ~ ".config" }}'
owner: '{{ ansible_user_uid }}'
group: '{{ ansible_user_gid }}'
lstrip_blocks: true
trim_blocks: true
mode: 0640
validate: >-
sh -c "cat {{ansible_user_dir}}/.config/sway/conf.d/* %s > /tmp/sway; if sway --config /tmp/sway --validate 2>&1 | grep -q sway/config.c; then >&2 echo \"Error validating sway configuration\"; rm /tmp/sway; exit 1; else rm /tmp/sway; exit 0; fi"
loop:
- 51-swaylock_keybindings
any_errors_fatal: true

View file

@ -0,0 +1,13 @@
{% for section in swaylock_keybindings %}
{% if section.mode != "normal" %}
mode {{ section.mode }} {
{% endif %}
{% for bind in section.bindings %}
bindsym {{ bind.bindsym }} {{ bind.action}}
{% endfor %}
{% if section.mode != "normal" %}
}
{% endif %}
{% endfor %}

12
templates/config.j2 Normal file
View file

@ -0,0 +1,12 @@
# {{ ansible_managed }}
{% if swaylock_flags is defined %}
{% for flag in swaylock_flags %}
{{ flag }}
{% endfor %}
{% endif %}
{% if swaylock_options is defined %}
{% for key, value in swaylock_options.items() %}
{{ key }}={{ value }}
{% endfor %}
{% endif %}