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
Foreman: add options to support backwards compatibility with script #67070
Conversation
The test
The test
|
aa22c3d
to
8bdbbc8
Compare
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.
shipit
@AlanCoding, @jainnikhil30 and I have been chatting about this PR. If I understand @AlanCoding and @jainnikhil30 correctly, it sounds like they are proposing that we use keyed_groups to get backwards compatibility with groups. Here's my attempt at using Groups returned by the script: Groups returned by the plugin: Comparing the two sets of groups:
As far as I can tell, |
Backwards compatibility with groups was one part of this PR, hostvars was the other part. As far as I can tell, there isn't a way to 'construct' the hostvars in a backwards compatible way without using custom logic like I've added here. |
@jladdjr you can apply lower() to the key, jinja2 filter and python builtins are still available for you to get the same names. Also the extra underscore is the default separator, just use '' instead. As for variables, look at the compose system, from a quick reading of the code you should be able to do the same, set the 'foreman' prefix and use the other options to get all the same parameters/variables. |
@bcoca - awesome, thanks for the tips, giving those a shot |
@bcoca (cc @AlanCoding) took a look at the compose system (this is the related code, afaict) and the TLDR is that I'm not seeing a way to re-create what the script returns. Details below. To go into a bit more detail about what kind of parity issues I'm seeing.. Script hostvars look like this:
Looking at the compose system, I'm not seeing a way to build the top-level dictionary I mentioned:
If I try to use something like this in
.. the compose system just creates a static dictionary mirroring what I have under compose. In order to build hostvars that form a dictionary, the compose system would need to do some recursion (which I don't see present right now). Sorry for being a bit verbose - wanted to make sure I captured the scenario I'm trying to reproduce. Am I missing something here? Is compose able to fill out a dictionary of hostvars? |
Okay, I found a way to build the foreman groups using
So we can drop the changes here that build up groups. It still seems like the hostvar related changes are needed, though. |
8bdbbc8
to
4861aad
Compare
- Places hostvars in a dictionary with keys `foreman`, `foreman_facts`, and `foreman_params` | ||
type: boolean | ||
default: False | ||
version_added: '2.10' |
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.
maybe you could add the deprecated flag to this data?
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.
You mean, we should basically say in advance something like, "in 2.13, we'll drop support for this (and officially break with the old script)" - is that what you mean?
@wenottingham - do we have a general policy about when awx can officially break ties with the old inv. scripts? Guess the answer to that may vary for each inventory source.
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.
why would it be deprecated? is it that complex to maintain it as an option?
It's a breaking change regardless of when it happens.
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.
@AlanCoding per @wenottingham's note, it seems like this option is something that we'll need to maintain for a while unless (1) there's some other way we plan on providing compatibility in the future (I can't think of any) or (2) we plan on actually transitioning the awx foreman plugin towards its vanilla behavior (but that would be a breaking change for awx users and I'm not sure we plan on ever doing that). In short, doesn't seem like we are planning on deprecating support for the new legacy_hostvars
option.
This comment has been minimized.
This comment has been minimized.
This doesn't have the changes to get the legacy groups anymore, so that should make this simpler. +1 I absolutely advocate for merging this. |
The jinja syntax (while a bit unwieldy) follows the old script's approach to creating groups pretty closely. I'm actually feeling pretty good about using Here's the final version of the plugin arguments that I came up with, btw:
When I pair the changes made to the plugin here, with these changes in awx -- which basically mirror the above plugin config snippet -- I confirmed that I'm able build the exact same inventory in awx when I run an inventory import with the script and plugin. Think we should ship it! |
@sjha4 thoughts? |
What's needed in order to move this forward? The awx team is trying to get this in so that the foreman plugin can be adopted for Tower 3.7. |
ready_for_review |
From the foreman inventory api perspective, this looks fine to me since all of the data massaging is happening post the inventory call to foreman and outside foreman. If the pre-change and post-change o/p are the same, the change looks good to me.. |
Well..did not realize this was the plugin script and the larger change is to move awx to use this as the source..in which case the plugin script needs to use the foreman inventory report api like the https://github.com/ansible/ansible/blob/devel/contrib/inventory/foreman.py script does.. |
@sjahl sounds like a good idea, but not a blocker for getting this in, right? Would vote for handling that separately. The plugin currently breaks backwards compatibility w/out this change. We can move forward on other breaking changes / things needed for parity after getting this in. Making sure hostvars have parity is a pretty fundamental first step towards overall parity. |
@jladdjr : sounds good.. 👍 |
sweet, in that case.. motion made, seconded, ship_it? |
shipit |
superseded by theforeman/foreman-ansible-modules#591 |
SUMMARY
Introduces two new options -
legacy_groups
andlegacy_hostvars
- to the foreman plugin. When both options are enabled, the plugin returns the same groups and hostvars returned by the foreman script.Introducing this backwards compatibility in anticipation of awx adopting the foreman plugin (need a way to switch over to the plugin while still preserving the inventory structure that was present with the old script).
c.f. ansible/awx#3509
ISSUE TYPE
COMPONENT NAME
foreman inventory plugin
ADDITIONAL INFORMATION
Overview of changes:
legacy_groups:
environment
,location
,organization
hostvarscontent_facet_attributes
(i.e.lifecycle_environment
andcontent_view
)legacy_hostvars:
foreman
keyforeman_params
keyforeman_facts
already compatible with foreman script - left this unchanged