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 #67 #86

Merged
merged 6 commits into from
Sep 16, 2021
Merged

fixes #67 #86

merged 6 commits into from
Sep 16, 2021

Conversation

itdependsnetworks
Copy link
Contributor

I am not sure populate_root is the best name, so welcome to hear suggestions. I updated the testing for similar tests.

@jvanderaa
Copy link
Contributor

I want to say something like populate_facts or add_to_host_facts as part of it.

@itdependsnetworks
Copy link
Contributor Author

I don't like using the term facts, since it would indicate the intention is to modify facts, when it is the root keys, I know there is a better term, but can't see it yet.

@pszulczewski
Copy link
Contributor

pszulczewski commented Sep 13, 2021

I like the idea, but I wonder if Boolean will be sufficient?
Let's imagine two GQL queries, different filtering, but the same endpoint, what means that root elements are the same and when added with .get("data") one can overwrite the other.
Maybe instead of bool better to define key_name where the data would be added "to facts" under that key?

@itdependsnetworks
Copy link
Contributor Author

I believe What you described is the default?

@pszulczewski
Copy link
Contributor

OK, I see:
Beware, that the root keys provided by the query will overwrite any root keys already present, leverage the GraphQL alias feature to avoid issues.
So GQL alias is the recommended way to avoid overwrite, that's fine then. 👍

plugins/modules/query_graphql.py Outdated Show resolved Hide resolved
# the data structure, e.g. hostvars[inventory_hostname]
if args.get("populate_root"):
results["ansible_facts"] = nautobot_response.json.get("data")
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need the else here as we should be returning the data regardless. The flag should just set the facts or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had that at first, it seemed like duplicate, what say everyone else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's go ahead and remove the else, remove the indent for the results. Then the data key will be populated regardless, whether it has data or it is None.

@pszulczewski
Copy link
Contributor

I want to say something like populate_facts or add_to_host_facts as part of it.

I don't like using the term facts, since it would indicate the intention is to modify facts, when it is the root keys, I know there is a better term, but can't see it yet.

populate_root might not be intuitive, can be received as permission escalation.

I would suggest:
populate_hostvars
add_to_hostvars

I like the second one, intuitive and shorter.

- name: Obtain list of devices at site in variables from Nautobot
networktocode.nautobot.query_graphql:
url: http://nautobot.local
token: thisIsMyToken
query: "{{ query_string }}"
variables: "{{ variables }}"
populate_root: "yes"
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't that be boolean true ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In ansible they are equivalent

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I know, unquoted yes is also evaluated as bool True.
This is more about documentation consistency, it's described as type bool in DOCUMENTATION section.
I was looking form a static-typing perspective, where bool is True or False without making assumptions about ansible internals, maybe unnecessarily. Anyway I don't have any issue with it, just a friendly suggestion.

@jvanderaa
Copy link
Contributor

@FragmentedPacket can you take a look.

plugins/action/query_graphql.py Outdated Show resolved Hide resolved
Co-authored-by: Josh VanDeraa <jv@networktocode.com>
jvanderaa
jvanderaa previously approved these changes Sep 16, 2021
@jvanderaa jvanderaa dismissed stale reviews from FragmentedPacket and themself via c2da247 September 16, 2021 16:08
@jvanderaa jvanderaa merged commit 76ff64e into nautobot:develop Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants