Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added executable parameter to the script module #36969

Merged
merged 3 commits into from
May 25, 2018

Conversation

tranceitionalMynd
Copy link
Contributor

SUMMARY

Added an interpreter parameter to the script module. This allows the script to be executed remotely using a specific interpreter under a system path or full path provided by the user.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

script module

ANSIBLE VERSION
ansible 2.6.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
ADDITIONAL INFORMATION

I used the same "space in filename/path logic" as the free_form parameter.

BEFORE:

ansible-doc script
> SCRIPT    (/usr/lib/python2.7/site-packages/ansible/modules/commands/script.py)

        The `script' module takes the script name followed by a list of space-delimited arguments.  The local script at path will be
        transferred to the remote node and then executed.  The given script will be processed through the shell environment on the remote
        node.  This module does not require python on the remote system, much like the [raw] module.  This module is also supported for
        Windows targets.

  * note: This module has a corresponding action plugin.

OPTIONS (= is mandatory):

- chdir
        cd into this directory on the remote node before running the script
        [Default: None]
        version_added: 2.4

- creates
        a filename, when it already exists, this step will *not* be run.
        [Default: None]
        version_added: 1.5

- decrypt
        This option controls the autodecryption of source files using vault.
        [Default: Yes]
        type: bool
        version_added: 2.4

= free_form
        Path to the local script file followed by optional arguments. There is no parameter actually named 'free form'; see the examples!
        [Default: None]

- removes
        a filename, when it does not exist, this step will *not* be run.
        [Default: None]
        version_added: 1.5

NOTES:
      * It is usually preferable to write Ansible modules than pushing scripts. Convert your script to an Ansible module for bonus
        points!
      * The ssh connection plugin will force pseudo-tty allocation via -tt when scripts are executed. pseudo-ttys do not have a stderr
        channel and all stderr is sent to stdout. If you depend on separated stdout and stderr result keys, please switch to a
        copy+command set of tasks instead of using script.
      * This module is also supported for Windows targets.
      * If the path to the local script contains spaces, it needs to be quoted.

AUTHOR: Ansible Core Team, Michael DeHaan
        METADATA:
          status:
          - stableinterface
          supported_by: core
 
EXAMPLES:
# Example from Ansible Playbooks
- script: /some/local/script.sh --some-arguments 1234

# Run a script that creates a file, but only if the file is not yet created
- script: /some/local/create_file.sh --some-arguments 1234
  args:
    creates: /the/created/file.txt

# Run a script that removes a file, but only if the file is not yet removed
- script: /some/local/remove_file.sh --some-arguments 1234
  args:
    removes: /the/removed/file.txt

AFTER:

ansible-doc script
> SCRIPT    (/usr/lib/python2.7/site-packages/ansible/modules/commands/script.py)

        The `script' module takes the script name followed by a list of space-delimited arguments.  The local script at path will be
        transferred to the remote node and then executed.  The given script will be processed through the shell environment on the remote
        node.  This module does not require python on the remote system, much like the [raw] module.  This module is also supported for
        Windows targets.

  * note: This module has a corresponding action plugin.

OPTIONS (= is mandatory):

- chdir
        cd into this directory on the remote node before running the script
        [Default: None]
        version_added: 2.4

- creates
        a filename, when it already exists, this step will *not* be run.
        [Default: None]
        version_added: 1.5

- decrypt
        This option controls the autodecryption of source files using vault.
        [Default: Yes]
        type: bool
        version_added: 2.4

= free_form
        Path to the local script file followed by optional arguments. There is no parameter actually named 'free form'; see the examples!
        [Default: None]

- interpreter
        Name or path of an interpreter to invoke the script with
        [Default: None]
        version_added: 2.6

- removes
        a filename, when it does not exist, this step will *not* be run.
        [Default: None]
        version_added: 1.5

NOTES:
      * It is usually preferable to write Ansible modules than pushing scripts. Convert your script to an Ansible module for bonus
        points!
      * The ssh connection plugin will force pseudo-tty allocation via -tt when scripts are executed. pseudo-ttys do not have a stderr
        channel and all stderr is sent to stdout. If you depend on separated stdout and stderr result keys, please switch to a
        copy+command set of tasks instead of using script.
      * This module is also supported for Windows targets.
      * If the path to the local script contains spaces, it needs to be quoted.

AUTHOR: Ansible Core Team, Michael DeHaan
        METADATA:
          status:
          - stableinterface
          supported_by: core
 
EXAMPLES:
# Example from Ansible Playbooks
- script: /some/local/script.sh --some-arguments 1234

# Run a script that creates a file, but only if the file is not yet created
- script: /some/local/create_file.sh --some-arguments 1234
  args:
    creates: /the/created/file.txt

# Run a script that removes a file, but only if the file is not yet removed
- script: /some/local/remove_file.sh --some-arguments 1234
  args:
    removes: /the/removed/file.txt

# Run a script using an interpreter in a non-system path
- script: /some/local/script
  args:
    interpreter: /some/remote/interpreter

# Run a script using an interpreter in a system path
- script: /some/local/script.py
  args:
    interpreter: python3

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. labels Mar 3, 2018
@tranceitionalMynd
Copy link
Contributor Author

I don't think the python3 label is applicable. Python 3 is only in the documentation example. Python 2.7 is the version I developed with and use.

@bcoca bcoca added this to the 2.7.0 milestone Mar 5, 2018
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Mar 5, 2018
@@ -48,6 +48,12 @@
version_added: "2.4"
required: false
default: null
interpreter:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To follow the conventions of shell and command, this should instead be executable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I've changed 'interpreter' to 'executable'.

@abadger abadger removed the python3 label Mar 6, 2018
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Mar 14, 2018
@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Mar 16, 2018
@tranceitionalMynd tranceitionalMynd changed the title Added interpreter parameter to the script module Added binaryparameter to the script module Mar 16, 2018
@tranceitionalMynd tranceitionalMynd changed the title Added binaryparameter to the script module Added binary parameter to the script module Mar 16, 2018
@tranceitionalMynd tranceitionalMynd changed the title Added binary parameter to the script module Added executable parameter to the script module Mar 16, 2018
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Mar 24, 2018
@ansibot ansibot added the affects_2.6 This issue/PR affects Ansible v2.6 label May 19, 2018
@maxamillion
Copy link
Contributor

shippable failures for FreeBSD user module are unrelated

@maxamillion maxamillion merged commit 04e3c96 into ansible:devel May 25, 2018
gothicx pushed a commit to gothicx/ansible that referenced this pull request Jun 9, 2018
* Added interpreter parameter to the script module

* Let required and default parameters get documented implicitly for binary parameter

* Renamed interpreter parameter to executable
jacum pushed a commit to jacum/ansible that referenced this pull request Jun 26, 2018
* Added interpreter parameter to the script module

* Let required and default parameters get documented implicitly for binary parameter

* Renamed interpreter parameter to executable
@ansible ansible locked and limited conversation to collaborators May 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.6 This issue/PR affects Ansible v2.6 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. module This issue/PR relates to a module. new_contributor This PR is the first contribution by a new community member. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants