commit
22e3335fa7
@ -0,0 +1,84 @@
|
||||
# Copyright 2017, David Wilson
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"""
|
||||
Classes to detect each case from [0] and prepare arguments necessary for the
|
||||
corresponding Runner class within the target, including preloading requisite
|
||||
files/modules known missing.
|
||||
|
||||
[0] "Ansible Module Architecture", developing_program_flow_modules.html
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import mitogen.core
|
||||
|
||||
|
||||
def parse_script_interpreter(source):
|
||||
"""
|
||||
Parse the script interpreter portion of a UNIX hashbang using the rules
|
||||
Linux uses.
|
||||
|
||||
:param str source: String like "/usr/bin/env python".
|
||||
|
||||
:returns:
|
||||
Tuple of `(interpreter, arg)`, where `intepreter` is the script
|
||||
interpreter and `arg` is its sole argument if present, otherwise
|
||||
:py:data:`None`.
|
||||
"""
|
||||
# Find terminating newline. Assume last byte of binprm_buf if absent.
|
||||
nl = source.find(b'\n', 0, 128)
|
||||
if nl == -1:
|
||||
nl = min(128, len(source))
|
||||
|
||||
# Split once on the first run of whitespace. If no whitespace exists,
|
||||
# bits just contains the interpreter filename.
|
||||
bits = source[0:nl].strip().split(None, 1)
|
||||
if len(bits) == 1:
|
||||
return mitogen.core.to_text(bits[0]), None
|
||||
return mitogen.core.to_text(bits[0]), mitogen.core.to_text(bits[1])
|
||||
|
||||
|
||||
def parse_hashbang(source):
|
||||
"""
|
||||
Parse a UNIX "hashbang line" using the syntax supported by Linux.
|
||||
|
||||
:param str source: String like "#!/usr/bin/env python".
|
||||
|
||||
:returns:
|
||||
Tuple of `(interpreter, arg)`, where `intepreter` is the script
|
||||
interpreter and `arg` is its sole argument if present, otherwise
|
||||
:py:data:`None`.
|
||||
"""
|
||||
# Linux requires first 2 bytes with no whitespace, pretty sure it's the
|
||||
# same everywhere. See binfmt_script.c.
|
||||
if not source.startswith(b'#!'):
|
||||
return None, None
|
||||
|
||||
return parse_script_interpreter(source[2:])
|
@ -1,4 +1,5 @@
|
||||
- import_playbook: remote_file_exists.yml
|
||||
- import_playbook: remote_expand_user.yml
|
||||
- import_playbook: low_level_execute_command.yml
|
||||
- import_playbook: make_tmp_path.yml
|
||||
- import_playbook: transfer_data.yml
|
||||
|
@ -0,0 +1,104 @@
|
||||
# related to issue 301. Essentially ensure remote_expand_user does not support
|
||||
# $HOME expansion.
|
||||
|
||||
- name: integration/action/remote_expand_user.yml
|
||||
hosts: test-targets
|
||||
any_errors_fatal: true
|
||||
tasks:
|
||||
- name: "Find out root's homedir."
|
||||
# Runs first because it blats regular Ansible facts with junk, so
|
||||
# non-become run fixes that up.
|
||||
setup: gather_subset=min
|
||||
become: true
|
||||
register: root_facts
|
||||
|
||||
- name: "Find regular homedir"
|
||||
setup: gather_subset=min
|
||||
register: user_facts
|
||||
|
||||
# ------------------------
|
||||
|
||||
- name: "Expand ~/foo"
|
||||
action_passthrough:
|
||||
method: _remote_expand_user
|
||||
kwargs:
|
||||
path: '~/foo'
|
||||
sudoable: false
|
||||
register: out
|
||||
- assert:
|
||||
that: out.result == '{{user_facts.ansible_facts.ansible_user_dir}}/foo'
|
||||
|
||||
- name: "Expand ~/foo with become active. ~ is become_user's home."
|
||||
action_passthrough:
|
||||
method: _remote_expand_user
|
||||
kwargs:
|
||||
path: '~/foo'
|
||||
sudoable: false
|
||||
register: out
|
||||
become: true
|
||||
- assert:
|
||||
that: out.result == '{{user_facts.ansible_facts.ansible_user_dir}}/foo'
|
||||
|
||||
- name: "Expand ~user/foo"
|
||||
action_passthrough:
|
||||
method: _remote_expand_user
|
||||
kwargs:
|
||||
path: '~{{ansible_user_id}}/foo'
|
||||
sudoable: false
|
||||
register: out
|
||||
- assert:
|
||||
that: out.result == '{{user_facts.ansible_facts.ansible_user_dir}}/foo'
|
||||
|
||||
- name: "Expanding $HOME/foo has no effect."
|
||||
action_passthrough:
|
||||
method: _remote_expand_user
|
||||
kwargs:
|
||||
path: '$HOME/foo'
|
||||
sudoable: false
|
||||
register: out
|
||||
- assert:
|
||||
that: out.result == '$HOME/foo'
|
||||
|
||||
# ------------------------
|
||||
|
||||
- name: "sudoable; Expand ~/foo"
|
||||
action_passthrough:
|
||||
method: _remote_expand_user
|
||||
kwargs:
|
||||
path: '~/foo'
|
||||
sudoable: true
|
||||
register: out
|
||||
- assert:
|
||||
that: out.result == '{{user_facts.ansible_facts.ansible_user_dir}}/foo'
|
||||
|
||||
- name: "sudoable; Expand ~/foo with become active. ~ is become_user's home."
|
||||
action_passthrough:
|
||||
method: _remote_expand_user
|
||||
kwargs:
|
||||
path: '~/foo'
|
||||
sudoable: true
|
||||
register: out
|
||||
become: true
|
||||
|
||||
- assert:
|
||||
that: out.result == '{{root_facts.ansible_facts.ansible_user_dir}}/foo'
|
||||
|
||||
- name: "sudoable; Expand ~user/foo"
|
||||
action_passthrough:
|
||||
method: _remote_expand_user
|
||||
kwargs:
|
||||
path: '~{{ansible_user_id}}/foo'
|
||||
sudoable: true
|
||||
register: out
|
||||
- assert:
|
||||
that: out.result == '{{user_facts.ansible_facts.ansible_user_dir}}/foo'
|
||||
|
||||
- name: "sudoable; Expanding $HOME/foo has no effect."
|
||||
action_passthrough:
|
||||
method: _remote_expand_user
|
||||
kwargs:
|
||||
path: '$HOME/foo'
|
||||
sudoable: true
|
||||
register: out
|
||||
- assert:
|
||||
that: out.result == '$HOME/foo'
|
@ -0,0 +1,19 @@
|
||||
# https://github.com/dw/mitogen/issues/291
|
||||
- name: integration/runner/custom_bash_hashbang_argument.yml
|
||||
hosts: test-targets
|
||||
any_errors_fatal: true
|
||||
tasks:
|
||||
|
||||
- custom_bash_old_style_module:
|
||||
foo: true
|
||||
with_sequence: start=1 end={{end|default(1)}}
|
||||
register: out
|
||||
vars:
|
||||
ansible_bash_interpreter: "/usr/bin/env RUN_VIA_ENV=yes bash"
|
||||
|
||||
- assert:
|
||||
that: |
|
||||
(not out.changed) and
|
||||
(not out.results[0].changed) and
|
||||
out.results[0].msg == 'Here is my input' and
|
||||
out.results[0].run_via_env == "yes"
|
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
# This script exists to test the behavior of Stream.python_path being set to a
|
||||
# list. It sets an environmnt variable that we can detect, then executes any
|
||||
# arguments passed to it.
|
||||
export EXECUTED_VIA_ENV_WRAPPER=1
|
||||
if [ "${1:0:1}" == "-" ]; then
|
||||
exec "$PYTHON" "$@"
|
||||
else
|
||||
export ENV_WRAPPER_FIRST_ARG="$1"
|
||||
shift
|
||||
exec "$@"
|
||||
fi
|
Loading…
Reference in New Issue