Skip to content

Commit 09aa27a

Browse files
committed
ansible: initial mitogen_host_pinned strategy.
1 parent 863e1ae commit 09aa27a

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2017, David Wilson
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions are met:
5+
#
6+
# 1. Redistributions of source code must retain the above copyright notice,
7+
# this list of conditions and the following disclaimer.
8+
#
9+
# 2. Redistributions in binary form must reproduce the above copyright notice,
10+
# this list of conditions and the following disclaimer in the documentation
11+
# and/or other materials provided with the distribution.
12+
#
13+
# 3. Neither the name of the copyright holder nor the names of its contributors
14+
# may be used to endorse or promote products derived from this software without
15+
# specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
29+
from __future__ import absolute_import
30+
import os.path
31+
import sys
32+
33+
#
34+
# This is not the real Strategy implementation module, it simply exists as a
35+
# proxy to the real module, which is loaded using Python's regular import
36+
# mechanism, to prevent Ansible's PluginLoader from making up a fake name that
37+
# results in ansible_mitogen plugin modules being loaded twice: once by
38+
# PluginLoader with a name like "ansible.plugins.strategy.mitogen", which is
39+
# stuffed into sys.modules even though attempting to import it will trigger an
40+
# ImportError, and once under its canonical name, "ansible_mitogen.strategy".
41+
#
42+
# Therefore we have a proxy module that imports it under the real name, and
43+
# sets up the duff PluginLoader-imported module to just contain objects from
44+
# the real module, so duplicate types don't exist in memory, and things like
45+
# debuggers and isinstance() work predictably.
46+
#
47+
48+
BASE_DIR = os.path.abspath(
49+
os.path.join(os.path.dirname(__file__), '../../..')
50+
)
51+
52+
if BASE_DIR not in sys.path:
53+
sys.path.insert(0, BASE_DIR)
54+
55+
import ansible_mitogen.loaders
56+
import ansible_mitogen.strategy
57+
58+
59+
Base = ansible_mitogen.loaders.strategy_loader.get('host_pinned', class_only=True)
60+
61+
if Base is None:
62+
raise ImportError(
63+
'The host_pinned strategy is only available in Ansible 2.7 or newer.'
64+
)
65+
66+
class StrategyModule(ansible_mitogen.strategy.StrategyMixin, Base):
67+
pass

docs/ansible.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ Installation
7070
7171
The ``strategy`` key is optional. If omitted, the
7272
``ANSIBLE_STRATEGY=mitogen_linear`` environment variable can be set on a
73-
per-run basis. Like ``mitogen_linear``, the ``mitogen_free`` strategy exists
74-
to mimic the ``free`` strategy.
73+
per-run basis. Like ``mitogen_linear``, the ``mitogen_free`` and
74+
``mitogen_host_pinned`` strategies exists to mimic the ``free`` and
75+
``host_pinned`` strategies.
7576

7677
4. If targets have a restrictive ``sudoers`` file, add a rule like:
7778

0 commit comments

Comments
 (0)