Skip to content

th/ansible_independent#23

Merged
thom311 merged 19 commits into
masterfrom
th/ansible-independent
Jan 22, 2018
Merged

th/ansible_independent#23
thom311 merged 19 commits into
masterfrom
th/ansible-independent

Conversation

@thom311

@thom311 thom311 commented Jan 19, 2018

Copy link
Copy Markdown
Contributor

Refactor the module, to make it mostly independent of the ansible runtime.

The module is just one large python script. Ansible will execute it and communicated with it via stdout/stdin.

However, most of the stuff that the script does, is independent of ansible or how it is called.

Refactor the code, so that the parts that require the ansible environment can be replaced. This way, one could import the code in another python application, or we could run it from the command line and feed our own input format.

@thom311
thom311 requested a review from pcahyna January 19, 2018 14:00
@thom311
thom311 force-pushed the th/ansible-independent branch from da839db to de6ce89 Compare January 19, 2018 14:15
@thom311
thom311 requested a review from bengal January 19, 2018 14:15
Instead, pass the provider parameter.
It is really related to how the Cmd class operates during run. It
should not be handled by AnsibleUtil.
Make it more independent of AnsibleUtil.connections. Eventually,
we want to move parts to Cmd.
For now this looks more complicated then before. It will get better...
Now, that we only create the AnsibleUtil instance when we already
know that we run under ansible (not from unit tests), we can avoid
initializing the AnsibleModule lazily.
run() supports a --check mode (DRY_RUN) and a real mode,
where the real mode consists of a PRE_RUN that only simulates
the steps and a REAL_RUN.

Actualy changes can only happen during REAL_RUN (and we pretend
that they happen during DRY_RUN).

Fix handling of the change flag, is was broken previously.

Also, we need to set the is-changed flag to True before actually
invoking the action. Because, if we fail, we might fail_json()
right away, and need to correct changed flag.
@thom311
thom311 force-pushed the th/ansible-independent branch from de6ce89 to 068db05 Compare January 22, 2018 09:33
@bengal

bengal commented Jan 22, 2018

Copy link
Copy Markdown
Collaborator

Looks good to me.

@thom311
thom311 merged commit 068db05 into master Jan 22, 2018
thom311 added a commit that referenced this pull request Jan 22, 2018
Refactor the code, to make Cmd independent of ansible includes.
This would simplify to extend the library to run as stand-alone
application or to re-use parts without ansible.

Also, it better separates the code.

#23
@thom311
thom311 deleted the th/ansible-independent branch January 22, 2018 10:04
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.

2 participants