linux-system-roles / ssh

Ansible role for configuring ssh clients
https://linux-system-roles.github.io/ssh/
GNU Lesser General Public License v3.0
19 stars 17 forks source link

Confusing drop-in behavior #89

Closed skwde closed 1 year ago

skwde commented 1 year ago

When using drop-in names the behaviour is unexpected:

- name: Test
  hosts: rhel8
  gather_facts: false
  become: true
  roles:
    - role: fedora.linux_system_roles.ssh
      vars:
        ssh_skip_defaults: false
        ssh_config_file: '~/src/tests/ssh/ssh_config_RHEL8_test'
    - role: fedora.linux_system_roles.ssh
      vars:
        ssh_skip_defaults: true
        ssh_config_file: '~/src/tests/ssh/ssh_config.d_RHEL8_test/99-some-test.conf'
        ssh:
          Match:
            - Condition: "User {{ user_list | join(',') }}"
              SendEnv: 'SOME_VAR'

  vars:
    ssh_config_owner: 'user'
    ssh_config_group: 'user'
    ssh_config_mode: '0600'
    user_list:
      - 'user1'
      - 'user2'

This generates the default ~/src/tests/ssh/ssh_config_RHEL8_test including the drop-in part

#
# Ansible managed
#
# system_role:ssh

Include /etc/ssh/ssh_config.d/*.conf
Match User user1,user2
  SendEnv SOME_ENV

and an ~/src/tests/ssh/ssh_config.d_RHEL8_test/99-some-test.conf

#
# Ansible managed
#
# system_role:ssh

Match User user1,user2
  SendEnv SOME_ENV

which is correct.

So it seems that the ssh variable defined in the second call is already available in the first call...

Is there a way around this?

skwde commented 1 year ago

Turns out, undefined variable isn't causing an error but simply quitting silently. I added the missing variable definition user_list above.

The name of the issue stems from my lack of understanding of the difference between:

and

which caused me some headache earlier.

skwde commented 1 year ago

Ok, I keep getting confused by the behavior of the role. Now the output is again different. I adjusted playbooks + output above.

skwde commented 1 year ago

Setting ssh: {} to generate the default solves the issue