From 3166606a58b76f7314c705f6068f6a99e29c2fe5 Mon Sep 17 00:00:00 2001 From: s-hertel <19572925+s-hertel@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:56:23 -0400 Subject: [PATCH] ansible-pull, ansible-console - remove unused --list-hosts option --- ...149-add-flush-cache-for-adhoc-commands.yml | 3 +-- .../fragments/rm-unused-inventory-options.yml | 3 +++ lib/ansible/cli/console.py | 4 ++++ lib/ansible/cli/pull.py | 7 ++++--- .../pull-integration-test/gather_facts.yml | 2 -- .../test_empty_facts.yml | 5 ----- .../integration/targets/ansible-pull/runme.sh | 21 ++++++++++++++----- 7 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 changelogs/fragments/rm-unused-inventory-options.yml delete mode 100644 test/integration/targets/ansible-pull/pull-integration-test/gather_facts.yml delete mode 100644 test/integration/targets/ansible-pull/pull-integration-test/test_empty_facts.yml diff --git a/changelogs/fragments/84149-add-flush-cache-for-adhoc-commands.yml b/changelogs/fragments/84149-add-flush-cache-for-adhoc-commands.yml index 854d2628b64..9f407a9a0da 100644 --- a/changelogs/fragments/84149-add-flush-cache-for-adhoc-commands.yml +++ b/changelogs/fragments/84149-add-flush-cache-for-adhoc-commands.yml @@ -1,3 +1,2 @@ minor_changes: -- > - ansible, ansible-console, ansible-pull - add --flush-cache option (https://github.com/ansible/ansible/issues/83749). + - ansible cli - add --flush-cache option for ad-hoc commands (https://github.com/ansible/ansible/issues/83749). diff --git a/changelogs/fragments/rm-unused-inventory-options.yml b/changelogs/fragments/rm-unused-inventory-options.yml new file mode 100644 index 00000000000..919a793e5de --- /dev/null +++ b/changelogs/fragments/rm-unused-inventory-options.yml @@ -0,0 +1,3 @@ +bugfixes: +- > + ansible-pull, ansible-console - remove ignored --list-hosts option. diff --git a/lib/ansible/cli/console.py b/lib/ansible/cli/console.py index 6f355938aa5..af7279d1a1e 100755 --- a/lib/ansible/cli/console.py +++ b/lib/ansible/cli/console.py @@ -10,6 +10,7 @@ from __future__ import annotations # ansible.cli needs to be imported first, to ensure the source bin/* scripts run that code first from ansible.cli import CLI +import argparse import atexit import cmd import getpass @@ -116,6 +117,9 @@ class ConsoleCLI(CLI, cmd.Cmd): opt_help.add_runtask_options(self.parser) opt_help.add_tasknoplay_options(self.parser) + # remove unused default options + self.parser.add_argument('--list-hosts', help=argparse.SUPPRESS, action=opt_help.UnrecognizedArgument) + # options unique to shell self.parser.add_argument('pattern', help='host pattern', metavar='pattern', default='all', nargs='?') self.parser.add_argument('--step', dest='step', action='store_true', diff --git a/lib/ansible/cli/pull.py b/lib/ansible/cli/pull.py index ee24c9ff9aa..ca57fae7437 100755 --- a/lib/ansible/cli/pull.py +++ b/lib/ansible/cli/pull.py @@ -9,6 +9,7 @@ from __future__ import annotations # ansible.cli needs to be imported first, to ensure the source bin/* scripts run that code first from ansible.cli import CLI +import argparse import datetime import os import platform @@ -93,6 +94,9 @@ class PullCLI(CLI): self.parser.add_argument('args', help='Playbook(s)', metavar='playbook.yml', nargs='*') + # remove unused default options + self.parser.add_argument('--list-hosts', help=argparse.SUPPRESS, action=opt_help.UnrecognizedArgument) + # options unique to pull self.parser.add_argument('--purge', default=False, action='store_true', help='purge checkout after playbook run') self.parser.add_argument('-o', '--only-if-changed', dest='ifchanged', default=False, action='store_true', @@ -298,9 +302,6 @@ class PullCLI(CLI): if context.CLIARGS['diff']: cmd += ' -D' - if context.CLIARGS['flush_cache']: - cmd += ' --flush-cache' - os.chdir(context.CLIARGS['dest']) # redo inventory options as new files might exist now diff --git a/test/integration/targets/ansible-pull/pull-integration-test/gather_facts.yml b/test/integration/targets/ansible-pull/pull-integration-test/gather_facts.yml deleted file mode 100644 index 25305703c73..00000000000 --- a/test/integration/targets/ansible-pull/pull-integration-test/gather_facts.yml +++ /dev/null @@ -1,2 +0,0 @@ -- hosts: localhost - gather_facts: true diff --git a/test/integration/targets/ansible-pull/pull-integration-test/test_empty_facts.yml b/test/integration/targets/ansible-pull/pull-integration-test/test_empty_facts.yml deleted file mode 100644 index ab7559854bb..00000000000 --- a/test/integration/targets/ansible-pull/pull-integration-test/test_empty_facts.yml +++ /dev/null @@ -1,5 +0,0 @@ -- hosts: localhost - gather_facts: false - tasks: - - assert: - that: ansible_facts == {} diff --git a/test/integration/targets/ansible-pull/runme.sh b/test/integration/targets/ansible-pull/runme.sh index fd97c707f05..296dce35bd4 100755 --- a/test/integration/targets/ansible-pull/runme.sh +++ b/test/integration/targets/ansible-pull/runme.sh @@ -64,6 +64,19 @@ function pass_tests_multi { fi } +function pass_tests_unsupported_argument { + if [[ -z "$1" ]]; then + echo "Error: an argument is required." + exit 1 + fi + + local expected="ansible-pull: error: unrecognized arguments: ${1}" + if ! grep "${expected}" "${temp_log}"; then + echo "Did not fail as expected with: ${expected}" + exit 1 + fi +} + export ANSIBLE_INVENTORY export ANSIBLE_HOST_PATTERN_MISMATCH @@ -92,8 +105,6 @@ ANSIBLE_CONFIG='' ansible-pull -d "${pull_dir}" -U "${repo_dir}" conn_secret.yml # fail if we try do delete /var/tmp ANSIBLE_CONFIG='' ansible-pull -d var/tmp -U "${repo_dir}" --purge "$@" -# test flushing the fact cache -export ANSIBLE_CACHE_PLUGIN=jsonfile ANSIBLE_CACHE_PLUGIN_CONNECTION=./ -ansible-pull -d "${pull_dir}" -U "${repo_dir}" "$@" gather_facts.yml -ansible-pull -d "${pull_dir}" -U "${repo_dir}" --flush-cache "$@" test_empty_facts.yml -unset ANSIBLE_CACHE_PLUGIN ANSIBLE_CACHE_PLUGIN_CONNECTION +# test unsupported options +ansible-pull -d "${pull_dir}" -U "${repo_dir}" --list-hosts "$@" multi_play_1.yml 2> >(tee "${temp_log}") || true +pass_tests_unsupported_argument --list-hosts