Skip to content

Commit

Permalink
feat: add support for new mitogen. Older version with patching is sup…
Browse files Browse the repository at this point in the history
…ported.
  • Loading branch information
amarao committed Oct 7, 2024
1 parent 6ffa2d8 commit 2390532
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 356 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
This collection allows to use [Mitogen](https://github.com/mitogen-hq/mitogen)
strategy without the need to specify absolute path to the strategy file.

It also performs live patching for Mitogen restrictions in Ansible
versions, making it possible to use Mitogen with the current Ansible version.
It also performs live patching for oler versions of Mitogen (3.4), removing
Ansible version restrictions, making it possible to use Mitogen
on unsupported versions.

Tested versions of ansible-core:

* 2.14
* 2.15
* 2.16
* 2.17

It patches `ansible_mitogen` code and unpatches it
When needed, it patches `ansible_mitogen` code and unpatches it
back right after module import, so the original
files are kept intact.

If no patching needed, it just passes mitogen content as it is.

## Install
To use this collection, you need to install Mitogen:

Expand Down
13 changes: 11 additions & 2 deletions plugins/strategy/mitogen_free.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import importlib.metadata

from . import patching
try:
mitogen_version = importlib.metadata.version("mitogen")
except importlib.metadata.PackageNotFoundError:
raise ImportError("Unable to load mitogen module.")

with patching.patch_version():
if mitogen_version == "0.3.4":
from . import patching

with patching.patch_version():
from ansible_mitogen.plugins.strategy.mitogen_free import *
else:
from ansible_mitogen.plugins.strategy.mitogen_free import *
14 changes: 12 additions & 2 deletions plugins/strategy/mitogen_host_pinned.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@
short_description: Mitogen patching strategy
"""

from . import patching
import importlib.metadata

with patching.patch_version():
try:
mitogen_version = importlib.metadata.version("mitogen")
except importlib.metadata.PackageNotFoundError:
raise ImportError("Unable to load mitogen module.")

if mitogen_version == "0.3.4":
from . import patching

with patching.patch_version():
from ansible_mitogen.plugins.strategy.mitogen_host_pinned import *
else:
from ansible_mitogen.plugins.strategy.mitogen_host_pinned import *
14 changes: 12 additions & 2 deletions plugins/strategy/mitogen_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@
short_description: Mitogen patching strategy
"""

from . import patching
import importlib.metadata

with patching.patch_version():
try:
mitogen_version = importlib.metadata.version("mitogen")
except importlib.metadata.PackageNotFoundError:
raise ImportError("Unable to load mitogen module.")

if mitogen_version == "0.3.4":
from . import patching

with patching.patch_version():
from ansible_mitogen.plugins.strategy.mitogen_linear import *
else:
from ansible_mitogen.plugins.strategy.mitogen_linear import *
Loading

0 comments on commit 2390532

Please sign in to comment.