Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running with emtpy string as argument to --limit should fail #83264

Closed
1 task done
maetthew opened this issue May 17, 2024 · 3 comments
Closed
1 task done

Running with emtpy string as argument to --limit should fail #83264

maetthew opened this issue May 17, 2024 · 3 comments
Labels
affects_2.16 bug This issue/PR relates to a bug.

Comments

@maetthew
Copy link

Summary

When I run ansible-playbook with an empty string ("") as argument to --limit Ansible interprets that to all hosts. I would expect running --limit "" to fail. It fails if I give no argument or a string that doesn't match anything.

This is potentially dangerous in that for instance running CI/CD jobs with a variable as argument to --limit might cause job to run on all hosts in an inventory if the variable is never populated.

Issue Type

Bug Report

Component Name

core

Ansible Version

$ ansible --version
ansible [core 2.16.6]
  config file = None
  configured module search path = ['/home/redacted/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/redacted/.local/lib/python3.11/site-packages/ansible
  ansible collection location = /home/redacted/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/redacted/.local/bin/ansible
  python version = 3.11.9 (main, Apr 10 2024, 13:16:36) [GCC 13.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Configuration

# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = nvim
PAGER(env: PAGER) = /bin/sh -c "fmt -s -w 144 - | less"

OS / Environment

Debian 12

Steps to Reproduce

Run ansible-playbook -i inventory.ini --limit "" ping.yml

- hosts: all
  become: true
  tasks:
    - name: "Ping"
      ansible.builtin.ping:

Expected Results

I would expect running --limit with an empty string to fail. It fails if I give no argument or a string that doesn't match anything.

Actual Results

Ansible filters nothing, and instead runs against all hosts.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot ansibot added bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. affects_2.16 labels May 17, 2024
@ansibot
Copy link
Contributor

ansibot commented May 17, 2024

Files identified in the description:

None

If these files are incorrect, please update the component name section of the description or use the component bot command.

@sivel
Copy link
Member

sivel commented May 20, 2024

This is intentional behavior, and was codified in #62442

An empty limit is an alias for all.

@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label May 21, 2024
@bcoca
Copy link
Member

bcoca commented May 21, 2024

closing as per above

@bcoca bcoca closed this as completed May 21, 2024
@ansible ansible locked and limited conversation to collaborators Jun 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.16 bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

4 participants