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

Is it possible to set or override the inventory selection using Survey variables? #1354

Open
MarkLFT opened this issue Jul 20, 2023 · 8 comments

Comments

@MarkLFT
Copy link

MarkLFT commented Jul 20, 2023

We have a number of inventory lists, each with several servers, a very common configuration I am sure. But there are times we want to run a task against a single node, maybe a reboot etc.

Whilst I can easily override the host / group name using a survey variable, I still end up with needing to create a reboot task template for each inventory list. Is it possible to override the inventory selection using a survey variable or some other way at runtime?

@ansibleguy
Copy link
Contributor

Yes - you can supply the limit inside the task or task-template JSON field:

["--limit", "host1,host2"]

Also: I opened a specific feature-request for adding a --limit field: #1357

Regarding multiple inventories - you could try to also supply them using the 'JSON' field as those variables seem to be directly passed to Ansible.

@Ye-Min-Tun
Copy link

Yes, you can do with survery variable. And update the host variable in your playbook like the following:
host: "{{ your-survery-var-name }}"
This will prompt to set the variable when you run the task. You can enter 'all' or group name or host name. @MarkLFT

@MarkLFT
Copy link
Author

MarkLFT commented Jul 28, 2023

@Ye-Min-Tun The question was more about if we can select a different inventory file using a survey variable.

@decanthus314
Copy link

I second this. I am in a situation where it would be very helpful to have a selectable inventory at runtime.
Preferably a drop drop selector of existing inventories in the semaphore database instead of a survey variable string.

@ansibleguy
Copy link
Contributor

That way one should be able to 'override' the inventory-file configured in the 'task-template' when running a 'task' - that's the idea? Or did I get it wrong?
One should currently be able to supply multiple inventory lists using the JSON-field:

["--inventory", "inv2", "--inventory", "inv3"]

They should be passed 1-to-1 to the ansible-playbook execution

@Ye-Min-Tun
Copy link

Ye-Min-Tun commented Jul 31, 2023

@Ye-Min-Tun The question was more about if we can select a different inventory file using a survey variable.

Not sure about selecting the inventory file .
I just mentioned about selecting individual host or groups of hosts in a single inventory file at runtime.

@josefglatz
Copy link

Yes, you can do with survery variable. And update the host variable in your playbook like the following: host: "{{ your-survery-var-name }}" This will prompt to set the variable when you run the task. You can enter 'all' or group name or host name. @MarkLFT

Is it possible that variables can only by have underscores and no dashes? Because this just works when the variable has no dash in it.

@ansibleguy
Copy link
Contributor

@josefglatz See Ansible Documentation for variables

A variable name can only include letters, numbers, and underscores. Python keywords or playbook keywords are not valid variable names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants