-
Notifications
You must be signed in to change notification settings - Fork 9
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
Update Ansible Command #51
Conversation
Great stuff!!! A bunch of little nitpicks but great all around. |
Thanks for the review! I've updated some of the basics and will finish updating a couple of the other things which need just a little more testing tomorrow AM. Do you have any thoughts on the |
…ings Psi/issue 44 kc doc strings
@itdependsnetworks I removed the examples of passing in dynamic inventory and created Issue #55 to track a resolution for using dynamic inventory. The examples put together required that the dynamic inventory script directory be specified as an environment variable -- I'm thinking we'll want to ratify a strategy for how to declare this in a way that's a little cleaner than requiring the user to pass in an environment variable before execution. I'm thinking to add those examples back in inside of their own section in the README.md after we ratify a strategy and add the feature for dynamic inventory parsing. This PR should be ready to merge, spare unit tests. @dgarros, can you give me a yay or nay on how the code is implemented before I write those :)? |
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.
Looks great
Thanks for the review Damien! @itdependsnetworks -- are you good with us merging this? |
Yea, looks good to me. |
docs/ansible_command.md
Outdated
Two major caveats apply to using the `schema_enforcer_strict` variable. | ||
|
||
1) If the `schema_enforcer_strict` variable is set to true, the `schema_enforcer_schema_ids` variabe **MUST** be defined as a list of one and only one schema ID. If it is either not defined at all or defined as something other than a list with one element, an error will be printed to the screen and the tool will exit before performing any validations. | ||
2) The schema ID referenced by `schema_enforcer_schema_ids` **MUST** include all variables defined for the ansible host/group. If an ansible variable not defined in the schema is defined for a given host, schema validation will fail as, when strict mode is run, properties not defined in the schema are not allowed. |
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.
I am confused if this is testing the assimilation of data per ansible inventory, or just a particular file? If it is a file, how does it know what file to look for? How does this work with dynamic inventory?
How does defining the same data within multiple groups or group_vars/host_vars affect this?
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.
I've updated some of the verbiage to make this a little more clear.
- No matter where the inventory is rendered from, you end up with a data structure of the defined variables per host. This per-host data is what is validated for schema adherence on a per host basis.
- The tool doesn't yet officially support dynamic inventory. We've tested it and had it working, but we had to set environment variables to do so. I created an issue (Add options for parsing Ansible dynamic inventory #55) to track adding this feature in as I'd like have how a dynamic inventory is configured for use and how it's constructed clearly designed, documented, and articulated with it's own section and examples.
- The flattening of vars per host is done per ansible's rules for doing so
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.
Thanks for clarifying that for me. I went back and re-read it after the updates, and I would say that there are still 3 things that cause me not to read the docs that way, but to read it as validating the variables associated with a file
- The near identical schema and file names (makes sense that they have similar names, and not a problem if the next point is agreed upon)
- There is a single variable file hosting all of the data
- There aren't any ansible variables in the vars/schema (ansible_user, ansilbe_password)
I think adding an additional vars file (host or group) and adding some common variables used by the ansible framework would help push the reader into the interpretation you have defined above.
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.
Thanks for the input. Agreed. I'm going to go ahead and close this PR and submit another one with the example you've referenced in the interest of getting this one buttoned up :).
This PR Updates the
schema-enforcer ansible
command per #7, #34, #44 and and #47Overview
schema_enforcer_schema_ids
-- This was updated fromschema_enforcer_schemas
toschema_enforcer_schema_ids
for clarityschema_enforcer_strict
schema_enforcer_automap_default
-- This was updated fromschema_enforcer_automap
for clarity.The following were resolved and do not have an issue -- LMK if it would be best to create one. Since this was a total overhaul of the ansible command, I didn't know if it would be overkill to create specific issues for it right now.
--show-checks
argument has been added to theschema-enforcer ansible
command to show the schemas to which each host will be checked for adherence.schema-enforcer ansible
command which made it not actually evaluate schemas correctly has been remediated.Worth Noting
I added a few host-specific methods to the
AnsibleInventory
class as there were already a few host-specific methods which already existed on it. TheAnsibleInventory
class is very similar to theInstanceFileManager
class, except we have anInstanceFile
class as well. Many instances of theInstanceFile
class become attributes of theInstanceFileManager
class. Methods specific to an individual instance file are created on theInstanceFile
class, where methods that apply to many instance files are implemented on theInstanceFileManager
class.The
AnsibleInventory
class breaks away from this logic by implementing host-specific methods as well as those that are inventory specific on the sameAnsibleInventory
class itself, then expecting a Host object as input to the methods defined. It may make sense to create a specificAnsibleHost
class by subclassing ansible.inventory.host.Host. This would allow us to implement host-specific functions on a single host object (e.g.AnsibleHost
) and inventory specific functions on theAnsibleInventory
class, following the same architectural paradigm in use by theInstanceFileManager
andInstanceFile
classes. The tradeoff to this is that we'd have to override some built in functions which Ansible is currently providing, namely the population of hosts. I'm not sure what to do here, but thought it was worth bringing up that there is a divergence between the two architectures in the code base and that difference of approach creates an inconsistency which could lead to confusion on where to modify current methods, and where to put future methods..TODO
Worth Noting
section and 2) Validate that the way I implemented the code makes sense before I write the unit tests. I know this is contrary to TDD, but I've lately spent a lot of time un-necessarily re-writing unit tests to fit, then refit, then refit again a new architecture because the architecture wasn't well defined/ratified before I wrote them, so wanted to avoid that. -- updated, will add unit tests in another PR.