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
Fixes #24363 - Endpoint to display variables for role(s) #9
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ares @bastilian I think this one is quite critical for the latest release
candidates = File.read(role_file).scan(/{{(.*?)}}/).select do |param| | ||
param.first.scan(/item/) == [] && param.first.scan(/if/) == [] | ||
|
||
end.first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/first/flatten/
class VariablesExtractor | ||
class << self | ||
def extract_variables(role_path) | ||
role_files = Dir.glob("#{role_path}/**/*.yml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to scan for *.yaml files as well?
But more importantly, why getting variables by scanning the files like this? I plan to test some more, but it seems fragile to me. Variables from defaults/main.yml that are used just in templates are not imported. Wouldn't it be easier just to get them from the files in defaults?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes there is no 'defaults' folder, and we would still want to read the variables in such a case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think this is resolved. There are 3 main problems with this approach as far as I can see:
-
the variables that are declared in defaults/main.yml and used in templates are not detected
-
you are matching more that just variables, filters are imported as variables.
-
you are importing not just variables of the role, you are importing all the variables that are used in the role. Do we really want to import
ansible_distribution
as a role variable?
What about the following:
tasks:
- set_fact:
qpid_port: "{{ lookup('env', 'QPID_SERVICE_PORT') | int }}"
qpid_host: "{{ lookup('env', 'QPID_SERVICE_HOST') }}"
- name: "Wait for Qpid"
wait_for:
port: "{{ qpid_port }}"
host: "{{ qpid_host }}"
timeout: 600
- name: "Check for qpid queue"
command: "qpid-config -b {{ qpid_host }}:{{ qpid_port }} queues katello_event_queue"
register: queue_exist
ignore_errors: true
Should qpid_port
and qpid_host
be imported as variables?
There should be an endpoint at the proxy to display all variables for a role and for many roles, so Foreman can use that to import the variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to only parse 'defaults/**/*.yaml/yml', thanks for the review @xprazak2 !
Merging for the time being |
There should be an endpoint at the proxy to display all variables for a
role and for many roles, so Foreman can use that to import the
variables.