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

Fixes #24363 - Endpoint to display variables for role(s) #9

Merged
merged 1 commit into from Oct 22, 2018

Conversation

dLobatog
Copy link
Member

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.

Copy link
Member Author

@dLobatog dLobatog left a 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
Copy link
Contributor

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")
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

@xprazak2 xprazak2 Oct 21, 2018

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.
Copy link
Member Author

@dLobatog dLobatog left a 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 !

@dLobatog dLobatog merged commit 02ea3eb into theforeman:master Oct 22, 2018
@dLobatog
Copy link
Member Author

Merging for the time being

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