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 #27937 - API for Ansible Inventory template scheduling #299

Merged
merged 1 commit into from Oct 17, 2019

Conversation

ofedoren
Copy link
Member

Requires theforeman/foreman#6875.

To use the endpoint there should exist the Ansible Inventory report template (part of this PR)

@sjha4
Copy link

sjha4 commented Sep 16, 2019

We would probably also need the below fields ( or decide which ones we need from the below response) from the earlier setup:

"foreman": {
          "architecture_id": 1,
          "architecture_name": "x86_64",
          "build": "False",
          "capabilities": [
            "build"
          ],
          "certname": "samir",
          "comment": "None",
          "compute_profile_id": "None",
          "compute_profile_name": "None",
          "compute_resource_id": "None",
          "compute_resource_name": "None",
          "content_facet_attributes": {
            "applicable_module_stream_count": 0,
            "applicable_package_count": 0,
            "content_source": "None",
            "content_source_id": "None",
            "content_source_name": "None",
            "content_view": {
              "id": 1,
              "name": "Default Organization View"
            },
            "content_view_id": 1,
            "content_view_name": "Default Organization View",
            "errata_counts": {
              "bugfix": 0,
              "enhancement": 0,
              "security": 0,
              "total": 0
            },
            "id": 1,
            "kickstart_repository": "None",
            "kickstart_repository_id": "None",
            "kickstart_repository_name": "None",
            "lifecycle_environment": {
              "id": 1,
              "name": "Library"
            },
            "lifecycle_environment_id": 1,
            "lifecycle_environment_name": "Library",
            "upgradable_module_stream_count": 0,
            "upgradable_package_count": 0,
            "uuid": "None"
          },
          "created_at": "2019-09-10 18:56:49 UTC",
          "disk": "None",
          "domain_id": "None",
          "domain_name": "None",
          "enabled": "True",
          "environment_id": "None",
          "environment_name": "None",
          "global_status": 1,
          "global_status_label": "OK",
          "hostgroup_id": "None",
          "hostgroup_name": "None",
          "hostgroup_title": "None",
          "id": 1,
          "image_file": "",
          "image_id": "None",
          "image_name": "None",
          "installed_at": "None",
          "ip": "10.11.216.233",
          "ip6": "None",
          "last_compile": "2019-09-10 18:56:51 UTC",
          "last_report": "None",
          "location_id": 2,
          "location_name": "Default Location",
          "mac": "e4:70:b8:22:1d:66",
          "managed": "False",
          "medium_id": "None",
          "medium_name": "None",
          "model_id": "None",
          "model_name": "None",
          "name": "samir",
          "operatingsystem_id": 1,
          "operatingsystem_name": "CentOS 7",
          "organization_id": 1,
          "organization_name": "Default Organization",
          "owner_id": 4,
          "owner_name": "Admin User",
          "owner_type": "User",
          "provision_method": "build",
          "ptable_id": "None",
          "ptable_name": "None",
          "puppet_ca_proxy": "None",
          "puppet_ca_proxy_id": "None",
          "puppet_ca_proxy_name": "None",
          "puppet_proxy": "None",
          "puppet_proxy_id": "None",
          "puppet_proxy_name": "None",
          "puppet_status": 0,
          "pxe_loader": "None",
          "realm_id": "None",
          "realm_name": "None",
          "sp_ip": "None",
          "sp_mac": "None",
          "sp_name": "None",
          "sp_subnet_id": "None",
          "subnet6_id": "None",
          "subnet6_name": "None",
          "subnet_id": "None",
          "subnet_name": "None",
          "updated_at": "2019-09-10 18:56:54 UTC",
          "uptime_seconds": "None",
          "use_image": "None",
          "uuid": "None"
        }

@sjha4
Copy link

sjha4 commented Sep 16, 2019

@ofedoren : I am not sure if I am using the required param correctly, but with something like this: {'required':'all'} I get an error. Do you have an example curl with what the hash expects?

required = input('required').split(',').map { |r| r.strip.downcase }
inventory_data.merge!('Organization': host.organization) if (['all', 'organization'] & required).any?
inventory_data.merge!('Location': host.location) if (['all', 'location'] & required).any?
inventory_data.merge!('Hostgroup': host.hostgroup.name) if (['all', 'hostgroup'] & required).any?
Copy link

Choose a reason for hiding this comment

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

Suggested change
inventory_data.merge!('Hostgroup': host.hostgroup.name) if (['all', 'hostgroup'] & required).any?
inventory_data.merge!('Hostgroup': host.hostgroup.name) if (['all', 'hostgroup'] & required).any? && host.hostgroup

to avoid nil reference.

Copy link

Choose a reason for hiding this comment

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

So based on the new fields we want to add, I tried this:
['architecture_id','architecture_name'].each do |field| inventory_data.merge!(field=>host[field])

nor can I do something like inventory_data.merge!(field=>host.send(field))

It seems the Host::Managed::Jail does not like it.

Copy link
Member

@ares ares left a comment

Choose a reason for hiding this comment

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

few comments, please let me know if I should provide more details

- name: required
required: false
input_type: user
description: Comma-separated values that should be returned.
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be nicer user experience if we define separate input for every optional part, it would have restricted values yes no and would be required. That in UI should generate select boxes to chose from yes/no.

We could also use this chance to add default values to inputs (that would be PR to Foreman core)

Copy link
Member Author

Choose a reason for hiding this comment

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

@sjha4
Copy link

sjha4 commented Sep 17, 2019

Below is the list of fields available on the host model so they can be pulled into the report:
https://gist.github.com/sjha4/eee846297dcf051e9a4f14198b444309
I am looking at the Content Facet Attributes data that is needed to create the content view and lifecycle groups for hosts.

@ofedoren
Copy link
Member Author

ofedoren commented Sep 19, 2019

The third commit requires Katello/katello#8356.

@ofedoren
Copy link
Member Author

The fourth commit requires theforeman/foreman#7052.

@ofedoren
Copy link
Member Author

Below is the list of fields available on the host model so they can be pulled into the report:
https://gist.github.com/sjha4/eee846297dcf051e9a4f14198b444309
I am looking at the Content Facet Attributes data that is needed to create the content view and lifecycle groups for hosts.

@sjha4, that's quite a big list and I'm not sure if we should add a separate template input for each field.

@ares, how can we choose what should be in the report (or at least as template inputs) and what should be not?

@sjha4
Copy link

sjha4 commented Sep 19, 2019

@ofedoren : Right..It's >70 fields in the intial API call I was testng with. I am not sure we need all the details on the report.
We do need the content_facet_attributes. I have a PR in katello Katello/katello#8357 and a dummy report here: http://pastebin.test.redhat.com/798999 with content_facety_attributes that we would need to add to this report.

@ofedoren
Copy link
Member Author

@sjha4, thanks for your input! I've added Content Facet Attributes to the template.

@ares
Copy link
Member

ares commented Sep 25, 2019

You can use https://projects.theforeman.org/issues/27937 for tracking this

Copy link
Member

@ares ares left a comment

Choose a reason for hiding this comment

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

Nice work so far, leaving few comments

Copy link
Member Author

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

Thanks for review! To simplify (I hope for testing purposes as well) I squashed the commits to one and to correspond with the issue.

@ares
Copy link
Member

ares commented Sep 30, 2019

looks well now, safe mode PRs seems to be in, this is now blocked on default values, description and format PRs in core

@ofedoren
Copy link
Member Author

ofedoren commented Oct 1, 2019

The template has been updated:

@ofedoren ofedoren changed the title [WIP] API for Ansible Inventory template scheduling Fixes #27937 - API for Ansible Inventory template scheduling Oct 8, 2019
@mmoll
Copy link
Contributor

mmoll commented Oct 11, 2019

please rebase

@ofedoren
Copy link
Member Author

@mmoll, rebased.

@mmoll
Copy link
Contributor

mmoll commented Oct 11, 2019

now it fails on rubocop

@ofedoren
Copy link
Member Author

@mmoll, thanks :) fixed.

@mmoll
Copy link
Contributor

mmoll commented Oct 11, 2019

almost there, permission missing :)

Copy link
Member

@ares ares left a comment

Choose a reason for hiding this comment

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

This should probably resuse existing core permission for generating reports

@@ -82,7 +82,7 @@
:edit_ansible_variables, :destroy_ansible_variables]

role 'Ansible Tower Inventory Reader',
[:view_hosts, :view_hostgroups, :view_facts],
[:view_hosts, :view_hostgroups, :view_facts, :view_schedule],
Copy link
Member

Choose a reason for hiding this comment

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

Do we need separate view_schedule permission? I think this should be the same permission as for genertimg regular report

Copy link
Member Author

Choose a reason for hiding this comment

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

I've reused generate_report_tempaltes permission if it makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

yes, that's exactly what I had in mind

@ares
Copy link
Member

ares commented Oct 16, 2019

[test foreman_ansible]

Copy link
Member

@ares ares left a comment

Choose a reason for hiding this comment

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

Tested, ack pending jenkins

@ares
Copy link
Member

ares commented Oct 17, 2019

Thanks @ofedoren, merging!

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