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

Ansible runner allow to run roles without playbook #17757

Conversation

Ladas
Copy link
Contributor

@Ladas Ladas commented Jul 25, 2018

Ansible runner allow to run roles without playbook

The example usage is:

Ansible::Runner.run_role(ext_management_system.parent_manager.ansible_env_vars,
                             {
                               :vpc_id                      => options["vpc_id"],
                               :security_group_name         => options["security_group_name"],
                               :security_group_description  => options["security_group_description"],
                               :security_group_rules        => options["security_group_rules"],
                               :security_group_rules_egress => options["security_group_rules_egress"],
                             },
                             "create_security_group",
                             :roles_path => File.join(ext_management_system.parent_manager.ansible_root, "roles")

    )

So we run a role directly and we do not need to write a playbook like https://github.com/ManageIQ/manageiq-providers-amazon/pull/453/files#diff-043bd0af7eaf90b61c703f5629a40845 , since that will be generated for us

Ladas added 3 commits July 25, 2018 15:29
Allow to run role without playbook
Allow to run run_role via queue
Fix the queue methods args
@Ladas Ladas force-pushed the ansible_runner_allow_to_run_roles_without_playbook branch from 300612c to 18f9abb Compare July 25, 2018 13:29
@Ladas
Copy link
Contributor Author

Ladas commented Jul 25, 2018

@miq-bot assign @agrare
@miq-bot add_label enhancement

@Ladas
Copy link
Contributor Author

Ladas commented Jul 25, 2018

@miha-plesko @borod108 this way, we can call the roles directly and we can delete the simple playbooks

run_via_cli(env_vars, extra_vars, :playbook_path => playbook_path)
end

def run_role(env_vars, extra_vars, role_name, roles_path:, role_skip_facts: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Galaxy roles, roles_path argument won't mean anything because they are installed globally AFAIK. We would probably want to make it optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, but right now ansible-runner looks only in the working dir, I need to create an Issue so it also checks the system roles/galaxy roles. So right now, we need to provide the right path ourselves (or I could put there a default value ?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agrare although we probably didn't want to install the roles in a global dir, because of the possible conflicts with other providers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right we'll need to look into if we can install galaxy roles to directories other than a global location. Ideally we would scope this to per-provider repos so nothing conflicts.


if roles_path
role_params[:"roles-path"] = roles_path
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest we inline it with

role_params[:"roles-path"] = roles_path if roles_path

end

if role_skip_facts
role_params[:"role-skip-facts"] = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should set to true here instead nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, this argument is without value

so it's like ansible-runner XY vs. ansible-runner XY --role-skip-facts

Ladas added 2 commits July 25, 2018 17:29
Simplify the role param condition
Fix circular argument reference
@miq-bot
Copy link
Member

miq-bot commented Jul 25, 2018

Checked commits Ladas/manageiq@93bdb15~...00bd9be with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🍰

@agrare agrare merged commit 00bd9be into ManageIQ:master Jul 26, 2018
agrare added a commit that referenced this pull request Jul 26, 2018
…s_without_playbook

Ansible runner allow to run roles without playbook
@agrare agrare added this to the Sprint 91 Ending Jul 30, 2018 milestone Jul 26, 2018
unless File.exist?(path)
raise "File doesn't exist: #{path}"
end
end

def ansible_command(base_dir)
# TODO add possibility to use custom path, e.g. from virtualenv
"ansible-runner run #{base_dir} --json -i result"
"ansible-runner run #{base_dir} --json -i result --hosts localhost"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future stuff but we might want to make the --hosts configurable if people want to run playbooks on other systems i.e. post-provisioning

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

Successfully merging this pull request may close these issues.

4 participants