Skip to content

Instantly share code, notes, and snippets.

@ogaida
Last active June 4, 2024 20:57
Show Gist options
  • Save ogaida/5867d3fb929ff23341b0b627890db6b8 to your computer and use it in GitHub Desktop.
Save ogaida/5867d3fb929ff23341b0b627890db6b8 to your computer and use it in GitHub Desktop.
set hosts via hosts variable

all host call

ansible-playbook playbook_debug.yml --list-hosts

limit hosts with the hosts variable and use a regex with ~

see https://docs.ansible.com/ansible/latest/inventory_guide/intro_patterns.html in this example only hosts are affected who match the regex: f\d.*-imap00\d . this is usefull if you use import_playbook to import the playbook playbook_debug.yml

ansible-playbook playbook_debug.yml -e hosts=":&~f\d.*-imap00\d$" --list-hosts    

the standard way also works

good to know that the playbooks also works the standard way

ansible-playbook playbook_debug.yml -l '~f3mb-imap' --list-hosts
---
- name: execute playbook_debug.yml
import_playbook: playbook_debug.yml
vars:
hosts: ':&~f\d.*-imap00\d$'
---
- hosts: "all{{ hosts|default('') }}"
vars:
a: hallo Maksym
tasks:
- name: debug
debug:
msg: "{{ a }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment