Skip to content

Commit

Permalink
tests: Access getent_* list from ansible_facts
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Jelen <[email protected]>
  • Loading branch information
Jakuje authored and richm committed Jan 8, 2024
1 parent 5359222 commit 50e46d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

- name: Make sure the ~/.ssh/ directory exists and has expected permissions
file:
path: "{{ getent_passwd[ssh_user][4] }}/.ssh/"
path: "{{ ansible_facts['getent_passwd'][ssh_user][4] }}/.ssh/"
state: directory
mode: "0700"
owner: "{{ ssh_user }}"
group: "{{ ssh_user }}"
when:
- ssh_user is not none
- getent_passwd is defined
- ansible_facts['getent_passwd'] is defined

- name: Generate the configuration file
template:
Expand Down Expand Up @@ -57,8 +57,9 @@
__ssh_config_file: >-
{% if ssh_config_file is not none %}
{{ ssh_config_file }}
{% elif ssh_user is not none and getent_passwd is defined %}
{{ getent_passwd[ssh_user][4] }}/.ssh/config
{% elif ssh_user is not none and
ansible_facts['getent_passwd'] is defined %}
{{ ansible_facts['getent_passwd'][ssh_user][4] }}/.ssh/config
{% else %}
{% if ssh_drop_in_name is not none and __ssh_supports_drop_in %}
{{ __ssh_drop_in_template | replace("{name}", ssh_drop_in_name) }}
Expand All @@ -77,7 +78,8 @@
__ssh_config_group: >-
{% if ssh_config_group is not none %}
{{ ssh_config_group }}
{% elif ssh_user is not none and getent_passwd is defined %}
{% elif ssh_user is not none and
ansible_facts['getent_passwd'] is defined %}
{{ ssh_user }}
{% else %}
root
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_user_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
- name: Verify the configuration file was created with right content
vars:
ssh_test_config_file:
"{{ getent_passwd[username][4] }}/.ssh/config"
"{{ ansible_facts['getent_passwd'][username][4] }}/.ssh/config"

block:
- name: Download the created configuration file
Expand Down

0 comments on commit 50e46d7

Please sign in to comment.