File: run_ansible_playbook.py

package info (click to toggle)
python-mitogen 0.3.26-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,456 kB
  • sloc: python: 22,134; sh: 183; makefile: 74; perl: 19; ansic: 18
file content (52 lines) | stat: -rwxr-xr-x 1,256 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# Wrap ansible-playbook, setting up some test of the test environment.
import json
import os
import platform
import sys

GIT_BASEDIR = os.path.dirname(
    os.path.abspath(
        os.path.join(__file__, '..', '..')
    )
)

# Ensure VIRTUAL_ENV is exported.
os.environ.setdefault(
    'VIRTUAL_ENV',
    os.path.dirname(os.path.dirname(sys.executable))
)

# Set LANG and LC_ALL to C in order to avoid locale errors spammed by vanilla
# during exec_command().
os.environ.pop('LANG', None)
os.environ.pop('LC_ALL', None)


# Used by delegate_to.yml to ensure "sudo -E" preserves environment.
os.environ['I_WAS_PRESERVED'] = '1'

# Used by LRU tests.
os.environ['MITOGEN_MAX_INTERPRETERS'] = '3'

# Add test stubs to path.
os.environ['PATH'] = '%s%s%s' % (
    os.path.join(GIT_BASEDIR, 'tests', 'data', 'stubs'),
    os.pathsep,
    os.environ['PATH'],
)

extra = {
    'is_macos_controller': platform.system() == 'Darwin',
    'is_mitogen': os.environ.get('ANSIBLE_STRATEGY', '').startswith('mitogen'),
    'git_basedir': GIT_BASEDIR,
}

if 'ANSIBLE_ARGV' in os.environ:
    args = eval(os.environ['ANSIBLE_ARGV'])
else:
    args = ['ansible-playbook']

args += ['-e', json.dumps(extra)]
args += sys.argv[1:]
os.execvp(args[0], args)