From e5a2fe4c419740e9a709b07b064063f54277b983 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 23 Jul 2021 12:12:49 -0400 Subject: fix ssh cli defaults (#75245) * fix ssh cli defaults fixes #75221 --- changelogs/fragments/fix_cli_ssh_defaults.yml | 2 ++ lib/ansible/cli/arguments/option_helpers.py | 8 ++++---- lib/ansible/plugins/connection/ssh.py | 4 ++++ test/integration/targets/connection_ssh/runme.sh | 3 +++ .../targets/connection_ssh/test_ssh_defaults.cfg | 5 +++++ .../targets/connection_ssh/verify_config.yml | 21 +++++++++++++++++++++ 6 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/fix_cli_ssh_defaults.yml create mode 100644 test/integration/targets/connection_ssh/test_ssh_defaults.cfg create mode 100644 test/integration/targets/connection_ssh/verify_config.yml diff --git a/changelogs/fragments/fix_cli_ssh_defaults.yml b/changelogs/fragments/fix_cli_ssh_defaults.yml new file mode 100644 index 0000000000..65d26768c9 --- /dev/null +++ b/changelogs/fragments/fix_cli_ssh_defaults.yml @@ -0,0 +1,2 @@ +bugfixes: + - cli defaults for ssh args set to None as '' was bypassing normal default. diff --git a/lib/ansible/cli/arguments/option_helpers.py b/lib/ansible/cli/arguments/option_helpers.py index 1dad960de0..3a6f6adebb 100644 --- a/lib/ansible/cli/arguments/option_helpers.py +++ b/lib/ansible/cli/arguments/option_helpers.py @@ -256,13 +256,13 @@ def add_connect_options(parser): help="override the connection timeout in seconds (default=%s)" % C.DEFAULT_TIMEOUT) # ssh only - connect_group.add_argument('--ssh-common-args', default='', dest='ssh_common_args', + connect_group.add_argument('--ssh-common-args', default=None, dest='ssh_common_args', help="specify common arguments to pass to sftp/scp/ssh (e.g. ProxyCommand)") - connect_group.add_argument('--sftp-extra-args', default='', dest='sftp_extra_args', + connect_group.add_argument('--sftp-extra-args', default=None, dest='sftp_extra_args', help="specify extra arguments to pass to sftp only (e.g. -f, -l)") - connect_group.add_argument('--scp-extra-args', default='', dest='scp_extra_args', + connect_group.add_argument('--scp-extra-args', default=None, dest='scp_extra_args', help="specify extra arguments to pass to scp only (e.g. -l)") - connect_group.add_argument('--ssh-extra-args', default='', dest='ssh_extra_args', + connect_group.add_argument('--ssh-extra-args', default=None, dest='ssh_extra_args', help="specify extra arguments to pass to ssh only (e.g. -R)") parser.add_argument_group(connect_group) diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py index 7f67c798f8..a253809a79 100644 --- a/lib/ansible/plugins/connection/ssh.py +++ b/lib/ansible/plugins/connection/ssh.py @@ -93,6 +93,7 @@ DOCUMENTATION = ''' - name: ansible_ssh_common_args cli: - name: ssh_common_args + default: '' ssh_executable: default: ssh description: @@ -142,6 +143,7 @@ DOCUMENTATION = ''' version_added: '2.7' cli: - name: scp_extra_args + default: '' sftp_extra_args: description: Extra exclusive to the ``sftp`` CLI vars: @@ -155,6 +157,7 @@ DOCUMENTATION = ''' version_added: '2.7' cli: - name: sftp_extra_args + default: '' ssh_extra_args: description: Extra exclusive to the 'ssh' CLI vars: @@ -168,6 +171,7 @@ DOCUMENTATION = ''' version_added: '2.7' cli: - name: ssh_extra_args + default: '' reconnection_retries: description: Number of attempts to connect. default: 0 diff --git a/test/integration/targets/connection_ssh/runme.sh b/test/integration/targets/connection_ssh/runme.sh index 7e5953edac..cbadf1d5d1 100755 --- a/test/integration/targets/connection_ssh/runme.sh +++ b/test/integration/targets/connection_ssh/runme.sh @@ -68,3 +68,6 @@ ANSIBLE_SSH_TRANSFER_METHOD=piped ./posix.sh "$@" # test config defaults override ansible-playbook check_ssh_defaults.yml "$@" -i test_connection.inventory + +# ensure we can load from ini cfg +ANSIBLE_CONFIG=./test_ssh_defaults.cfg ansible-playbook verify_config.yml "$@" diff --git a/test/integration/targets/connection_ssh/test_ssh_defaults.cfg b/test/integration/targets/connection_ssh/test_ssh_defaults.cfg new file mode 100644 index 0000000000..362f946086 --- /dev/null +++ b/test/integration/targets/connection_ssh/test_ssh_defaults.cfg @@ -0,0 +1,5 @@ +[ssh_connection] +ssh_common_args=fromconfig +ssh_extra_args=fromconfig +scp_extra_args=fromconfig +sftp_extra_args=fromconfig diff --git a/test/integration/targets/connection_ssh/verify_config.yml b/test/integration/targets/connection_ssh/verify_config.yml new file mode 100644 index 0000000000..0bf7958682 --- /dev/null +++ b/test/integration/targets/connection_ssh/verify_config.yml @@ -0,0 +1,21 @@ +- hosts: localhost + gather_facts: false + vars: + ssh_configs: + - ssh_common_args + - ssh_extra_args + - sftp_extra_args + - scp_extra_args + tasks: + - debug: + msg: '{{item ~ ": " ~ lookup("config", item, plugin_type="connection", plugin_name="ssh")}}' + verbosity: 3 + loop: '{{ssh_configs}}' + tags: [ configfile ] + + - name: check config from file + assert: + that: + - 'lookup("config", item, plugin_type="connection", plugin_name="ssh") == "fromconfig"' + loop: '{{ssh_configs}}' + tags: [ configfile ] -- cgit v1.2.1