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

View file

@ -23,44 +23,5 @@
- "{{ ansible_os_family }}.yml" - "{{ ansible_os_family }}.yml"
- default.yml - default.yml
paths: paths:
- '{{ role_path }}/vars' - "{{ role_path }}/vars"
- '{{ playbook_dir }}/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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,11 +1,11 @@
--- ---
__sshd_packages: sshd_packages:
- openssh - openssh
- openssh-server - 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 # Fedora 32 ships with drop-in directory support so we touch
# just included file with highest priority by default and have # just included file with highest priority by default and have
# empty defaults # 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_defaults:
__sshd_os_supported: yes __sshd_os_supported: yes

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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