Skip defaults when appending configuration

This commit is contained in:
Jakub Jelen 2021-05-27 15:26:59 +02:00 committed by Jakub Jelen
parent a26ea56332
commit ad399343c9
4 changed files with 33 additions and 5 deletions

View file

@ -53,7 +53,8 @@ If set to *false*, the role will be completely disabled. Defaults to *true*.
If set to *true*, don't apply default values. This means that you must have a If set to *true*, don't apply default values. This means that you must have a
complete set of configuration defaults via either the `sshd` dict, or complete set of configuration defaults via either the `sshd` dict, or
`sshd_Key` variables. Defaults to *false*. `sshd_Key` variables. Defaults to *false* unless `sshd_namespace_append` is
set.
* `sshd_manage_service` * `sshd_manage_service`
@ -161,7 +162,8 @@ This is useful mostly when generating configuration snippets to Include.
By default (*null*), the role defines whole content of the configuration file By default (*null*), the role defines whole content of the configuration file
including system defaults. You can use this variable to invoke this role from including system defaults. You can use this variable to invoke this role from
other roles or from multiple places in a single playbook on systems that do not other roles or from multiple places in a single playbook on systems that do not
support drop-in directory. support drop-in directory. The `sshd_skip_defaults` is ignored and no system
defaults are used in this case.
When this variable is set, the role places the configuration that you specify When this variable is set, the role places the configuration that you specify
to configuration snippets in a existing configuration file under the given to configuration snippets in a existing configuration file under the given
@ -301,6 +303,33 @@ for example:
X11Forwarding: yes X11Forwarding: yes
``` ```
You can just append a configuration snippet with the `sshd_namespace_append`
option:
```
---
- hosts: all
tasks:
- name: Configure sshd to accept some useful environment variables
include_role:
name: ansible-sshd
vars:
sshd_namespace_append: accept-env
sshd:
# there are some handy environment variables to accept
AcceptEnv:
LANG
LS_COLORS
EDITOR
```
The following snippet will be appended to the default configuration file:
```
# BEGIN sshd system role managed block: namespace accept-env
Match all
AcceptEnv LANG LS_COLORS EDITOR
# END sshd system role managed block: namespace accept-env
```
More example playbooks can be found in [`examples/`](examples/) directory. More example playbooks can be found in [`examples/`](examples/) directory.
Template Generation Template Generation

View file

@ -6,7 +6,6 @@
name: ansible-sshd name: ansible-sshd
vars: vars:
sshd_namespace_append: accept-env sshd_namespace_append: accept-env
sshd_skip_defaults: true
sshd: sshd:
# there are some handy environment variables to accept # there are some handy environment variables to accept
AcceptEnv: AcceptEnv:

View file

@ -119,6 +119,8 @@
when: sshd_namespace_append is none when: sshd_namespace_append is none
- name: Update configuration file snippet - name: Update configuration file snippet
vars:
sshd_skip_defaults: true
blockinfile: blockinfile:
path: "{{ sshd_config_file }}" path: "{{ sshd_config_file }}"
owner: "{{ sshd_config_owner }}" owner: "{{ sshd_config_owner }}"

View file

@ -12,7 +12,6 @@
name: ansible-sshd name: ansible-sshd
vars: vars:
sshd_config_file: /etc/ssh/sshd_config sshd_config_file: /etc/ssh/sshd_config
sshd_skip_defaults: true
sshd_namespace_append: nm1 sshd_namespace_append: nm1
sshd: sshd:
AcceptEnv: EDITOR AcceptEnv: EDITOR
@ -26,7 +25,6 @@
name: ansible-sshd name: ansible-sshd
vars: vars:
sshd_config_file: /etc/ssh/sshd_config sshd_config_file: /etc/ssh/sshd_config
sshd_skip_defaults: true
sshd_namespace_append: nm2 sshd_namespace_append: nm2
sshd: sshd:
AcceptEnv: LS_COLORS AcceptEnv: LS_COLORS