-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Access to Variable values from Extra CLI field #1053
Comments
I have done similar functionality just by creating a limit_to variable in Environment that maps to hosts: {{ limit_to }} in the playbooks. Seems to work well |
Greetings! Actually I don't think so - as those survey-vars seem to be translated into 'extra-vars' that cannot be referenced in the context of the command-execution. I read into the codebase a little, but did not manage to find out how they are handled. I opened a specific feature-request for adding a |
@mmospanenko works like charm. Thanks a lot! |
Hey! Could you say what version of Ansible you had success with? I am not having any luck specifying |
just add UI variable, no any changes required in CLI template (it transmits automatically as -e), only name (Name field is important). Version from Semaphore Docker, doesn't matter more about this var https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#term-ansible_limit |
Hi, I'm trying this out and heavily rely on limit for my playbooks, but this doesn't seem to be working for me, although the survey variable is passed.
I'm using the semaphore:lastest, wondering if this is an Ansible issue, or if this special variable isn't meant to be set in this way. |
I don't see your input (all configs) so can't comment. Read the docs carefully and it should work. You should pass limit to Ansible |
@craigarms this is the same behavior I see. Ansible considers Taking Semaphore out of the equation altogether, I tested by attempting pass in I understand this directly conflicts with the reports of success above, so I would love to know what I'm missing. (Or for issue #1357 to be implemented 😄). |
The clean fix will be the 'limit form-field' feature: #1357 |
Here's another workaround. You need to create - name: Create limit inventory
hosts: localhost
gather_facts: false
tasks:
- name: Assert limit
run_once: yes
assert:
that:
- 'srv is defined'
fail_msg: 'srv variable must be present, e.g., `-e srv=xxx.local`'
quiet: yes
- name: Dynamic inventory
ansible.builtin.add_host:
hostname: '{{ srv }}'
groups: dynamic_limit
loop: "{{ srv.split(',') }}"
when: srv is defined and srv != ''
- name: Dynamic limit
hosts: dynamic_limit
tasks:
- debug:
msg: "Distribution: {{ ansible_distribution }} {{ ansible_distribution_version }}" |
Will be great to have ability to read values from UI Vars inside predefined Extra CLI Arguments template. For example, I want to ask a user what hosts he wants to deploy. We have all hosts inside inventory, but we should limit them for each run (-l arg).
How I see this implementation:
just add ability to use
jinja2
template for this (Extra CLI
) text field and access to variables.hosts
)['-l', '{{ hosts }}']
That's all, use case covered.
The text was updated successfully, but these errors were encountered: