Remove set_facts tasks not to polute global namespace

The usage of set_facts inside of roles is not recommended if
it is used for internal variables used only inside of the role.
It is recommended to use variables with smaller scope to avoid
inter-dependencies between different invocations of the same
role as demonstrated in the tests_alternative_file.yml later
in the patch series

ttps://github.com/oasis-roles/meta_standards#ansible-best-practices
This commit is contained in:
Jakub Jelen 2020-11-04 21:29:48 +01:00
parent 634d87490e
commit f32003f051
25 changed files with 72 additions and 115 deletions

View file

@ -41,21 +41,17 @@ sshd: {}
### VARS DEFAULTS
### The following are defaults for OS specific configuration in var files in
### this role. They should not be set directly by role users. If you really
### need to override them, use the corresponding, unprefixed variables (eg
### `sshd_packages` to override __sshd_packages).
__sshd_packages: []
__sshd_config_owner: root
__sshd_config_group: root
__sshd_config_mode: "0600"
__sshd_config_file: /etc/ssh/sshd_config
__sshd_binary: /usr/sbin/sshd
__sshd_service: sshd
### this role. They should not be set directly by role users.
sshd_packages: []
sshd_config_owner: root
sshd_config_group: root
sshd_config_mode: "0600"
sshd_binary: /usr/sbin/sshd
sshd_service: sshd
sshd_sftp_server: /usr/lib/openssh/sftp-server
### These variables are used by role internals and should not be used.
__sshd_sftp_server: /usr/lib/openssh/sftp-server
__sshd_defaults: {}
__sshd_os_supported: no
__sshd_sysconfig: false
__sshd_sysconfig_supports_crypto_policy: false
__sshd_sysconfig_supports_use_strong_rng: false

View file

@ -23,44 +23,5 @@
- "{{ ansible_os_family }}.yml"
- default.yml
paths:
- '{{ role_path }}/vars'
- '{{ playbook_dir }}/vars'
- name: Override OS defaults
block:
- name: Define sshd_packages
set_fact:
sshd_packages: "{{ __sshd_packages }}"
when: sshd_packages is not defined
- name: Define sshd_config_owner
set_fact:
sshd_config_owner: "{{ __sshd_config_owner }}"
when: sshd_config_owner is not defined
- name: Define sshd_config_group
set_fact:
sshd_config_group: "{{ __sshd_config_group }}"
when: sshd_config_group is not defined
- name: Define sshd_config_mode
set_fact:
sshd_config_mode: "{{ __sshd_config_mode }}"
when: sshd_config_mode is not defined
- name: Define sshd_config_file
set_fact:
sshd_config_file: "{{ __sshd_config_file }}"
when: sshd_config_file is not defined
- name: Define sshd_binary
set_fact:
sshd_binary: "{{ __sshd_binary }}"
when: sshd_binary is not defined
- name: Define sshd_service
set_fact:
sshd_service: "{{ __sshd_service }}"
when: sshd_service is not defined
- name: Define sshd_sftp_server
set_fact:
sshd_sftp_server: "{{ __sshd_sftp_server }}"
when: sshd_sftp_server is not defined
- name: Define sshd_sysconfig
set_fact:
sshd_sysconfig: "{{ __sshd_sysconfig }}"
when: sshd_sysconfig is not defined
- "{{ role_path }}/vars"
- "{{ playbook_dir }}/vars"

View file

@ -1,10 +1,10 @@
---
__sshd_config_mode: '0644'
sshd_config_mode: '0644'
# sshd is not installed by yum / AIX toolbox for Linux.
# You'll need to manually install them using AIX Web Download Packs.
__sshd_packages: []
__sshd_sftp_server: /usr/sbin/sftp-server
__sshd_config_group: system
sshd_packages: []
sshd_sftp_server: /usr/sbin/sftp-server
sshd_config_group: system
__sshd_defaults:
Subsystem: "sftp {{ sshd_sftp_server }}"
__sshd_os_supported: yes

View file

@ -1,9 +1,9 @@
---
__sshd_config_mode: '0644'
__sshd_packages:
sshd_config_mode: '0644'
sshd_packages:
- openssh
- openssh-server
__sshd_sftp_server: /usr/libexec/openssh/sftp-server
sshd_sftp_server: /usr/libexec/openssh/sftp-server
__sshd_defaults:
SyslogFacility: AUTHPRIV
PermitRootLogin: forced-commands-only

View file

@ -1,7 +1,7 @@
---
__sshd_packages:
sshd_packages:
- openssh
__sshd_sftp_server: /usr/lib/ssh/sftp-server
sshd_sftp_server: /usr/lib/ssh/sftp-server
__sshd_defaults:
AuthorizedKeysFile: .ssh/authorized_keys
ChallengeResponseAuthentication: no

View file

@ -1,8 +1,8 @@
---
# There is no package manager in CoreOS
__sshd_packages: []
__sshd_service: sshd
__sshd_sftp_server: internal-sftp
sshd_packages: []
sshd_service: sshd
sshd_sftp_server: internal-sftp
__sshd_defaults:
Subsystem: "sftp {{ sshd_sftp_server }}"
ClientAliveInterval: 180

View file

@ -1,8 +1,8 @@
---
__sshd_service: ssh
__sshd_packages:
sshd_service: ssh
sshd_packages:
- openssh-server
__sshd_config_mode: "0644"
sshd_config_mode: "0644"
__sshd_defaults:
Port: 22
Protocol: 2

View file

@ -1,9 +1,9 @@
---
__sshd_service: ssh
__sshd_packages:
sshd_service: ssh
sshd_packages:
- openssh-server
- openssh-sftp-server
__sshd_config_mode: "0644"
sshd_config_mode: "0644"
__sshd_defaults:
Port: 22
Protocol: 2

View file

@ -1,9 +1,9 @@
---
__sshd_service: ssh
__sshd_packages:
sshd_service: ssh
sshd_packages:
- openssh-server
- openssh-sftp-server
__sshd_config_mode: "0644"
sshd_config_mode: "0644"
__sshd_defaults:
Port: 22
Protocol: 2

View file

@ -1,9 +1,9 @@
---
__sshd_service: ssh
__sshd_packages:
sshd_service: ssh
sshd_packages:
- openssh-server
- openssh-sftp-server
__sshd_config_mode: "0644"
sshd_config_mode: "0644"
__sshd_defaults:
Port: 22
Protocol: 2

View file

@ -1,11 +1,11 @@
---
__sshd_packages:
sshd_packages:
- openssh
- openssh-server
__sshd_sftp_server: /usr/libexec/openssh/sftp-server
sshd_sftp_server: /usr/libexec/openssh/sftp-server
# Fedora 32 ships with drop-in directory support so we touch
# just included file with highest priority by default and have
# empty defaults
__sshd_config_file: /etc/ssh/sshd_config.d/00-ansible_system_role.conf
sshd_config_file: /etc/ssh/sshd_config.d/00-ansible_system_role.conf
__sshd_defaults:
__sshd_os_supported: yes

View file

@ -1,8 +1,8 @@
---
__sshd_packages:
sshd_packages:
- openssh
- openssh-server
__sshd_sftp_server: /usr/libexec/openssh/sftp-server
sshd_sftp_server: /usr/libexec/openssh/sftp-server
__sshd_defaults:
HostKey:
- /etc/ssh/ssh_host_rsa_key

View file

@ -1,5 +1,5 @@
---
__sshd_config_group: wheel
__sshd_config_mode: "0644"
__sshd_sftp_server: /usr/libexec/sftp-server
sshd_config_group: wheel
sshd_config_mode: "0644"
sshd_sftp_server: /usr/libexec/sftp-server
__sshd_os_supported: yes

View file

@ -1,7 +1,7 @@
---
__sshd_packages:
sshd_packages:
- net-misc/openssh
__sshd_sftp_server: /usr/lib64/misc/sftp-server
sshd_sftp_server: /usr/lib64/misc/sftp-server
__sshd_defaults:
Subsystem: "sftp {{ sshd_sftp_server }}"
# Replace tcp keepalive with unspoofable keepalive

View file

@ -1,7 +1,7 @@
---
__sshd_config_group: wheel
__sshd_config_mode: "0600"
__sshd_sftp_server: /usr/libexec/sftp-server
sshd_config_group: wheel
sshd_config_mode: "0600"
sshd_sftp_server: /usr/libexec/sftp-server
__sshd_defaults:
AuthorizedKeysFile: .ssh/authorized_keys
Subsystem: "sftp {{ sshd_sftp_server }}"

View file

@ -1,8 +1,8 @@
---
__sshd_packages:
sshd_packages:
- openssh
- openssh-server
__sshd_sftp_server: /usr/libexec/openssh/sftp-server
sshd_sftp_server: /usr/libexec/openssh/sftp-server
__sshd_defaults:
Protocol: 2
SyslogFacility: AUTHPRIV

View file

@ -1,8 +1,8 @@
---
__sshd_packages:
sshd_packages:
- openssh
- openssh-server
__sshd_sftp_server: /usr/libexec/openssh/sftp-server
sshd_sftp_server: /usr/libexec/openssh/sftp-server
__sshd_defaults:
HostKey:
- /etc/ssh/ssh_host_rsa_key

View file

@ -1,8 +1,8 @@
---
__sshd_packages:
sshd_packages:
- openssh
- openssh-server
__sshd_sftp_server: /usr/libexec/openssh/sftp-server
sshd_sftp_server: /usr/libexec/openssh/sftp-server
__sshd_defaults:
HostKey:
- /etc/ssh/ssh_host_rsa_key

View file

@ -1,7 +1,7 @@
---
__sshd_packages:
sshd_packages:
- openssh
__sshd_sftp_server: /usr/lib/ssh/sftp-server
sshd_sftp_server: /usr/lib/ssh/sftp-server
__sshd_defaults:
HostKey:
- /etc/ssh/ssh_host_rsa_key

View file

@ -1,8 +1,8 @@
---
__sshd_service: ssh
__sshd_packages:
sshd_service: ssh
sshd_packages:
- openssh-server
__sshd_config_mode: "0644"
sshd_config_mode: "0644"
__sshd_defaults:
Port: 22
Protocol: 2

View file

@ -1,9 +1,9 @@
---
__sshd_service: ssh
__sshd_packages:
sshd_service: ssh
sshd_packages:
- openssh-server
- openssh-sftp-server
__sshd_config_mode: "0644"
sshd_config_mode: "0644"
__sshd_defaults:
Port: 22
Protocol: 2

View file

@ -1,9 +1,9 @@
---
__sshd_service: ssh
__sshd_packages:
sshd_service: ssh
sshd_packages:
- openssh-server
- openssh-sftp-server
__sshd_config_mode: "0644"
sshd_config_mode: "0644"
__sshd_defaults:
Port: 22
Protocol: 2

View file

@ -1,9 +1,9 @@
---
__sshd_service: ssh
__sshd_packages:
sshd_service: ssh
sshd_packages:
- openssh-server
- openssh-sftp-server
__sshd_config_mode: "0644"
sshd_config_mode: "0644"
__sshd_defaults:
PasswordAuthentication: no
ChallengeResponseAuthentication: no

View file

@ -1,9 +1,9 @@
---
__sshd_service: ssh
__sshd_packages:
sshd_service: ssh
sshd_packages:
- openssh-server
- openssh-sftp-server
__sshd_config_mode: "0644"
sshd_config_mode: "0644"
__sshd_defaults:
ChallengeResponseAuthentication: no
UsePAM: yes

View file

@ -1,7 +1,7 @@
---
__sshd_packages:
sshd_packages:
- openssh
__sshd_sftp_server: /usr/lib/ssh/sftp-server
sshd_sftp_server: /usr/lib/ssh/sftp-server
__sshd_defaults:
AuthorizedKeysFile: .ssh/authorized_keys
UsePAM: yes