본문 바로가기

리눅스

[Ansible] ansible-doc 명령

반응형

ansible-doc 명령

 : plugin documentation tool

 

ansible-doc 사용법

ansible-doc -h
$ ansible-doc -h
usage: ansible-doc [-h] [--version] [-v] [-M MODULE_PATH] [--playbook-dir BASEDIR]
                   [-t {become,cache,callback,cliconf,connection,httpapi,inventory,lookup,netconf,shell,vars,module,strategy,role,keyword}] [-j]
                   [-r ROLES_PATH] [-e ENTRY_POINT | -s | -F | -l | --metadata-dump]
                   [plugin [plugin ...]]

plugin documentation tool

positional arguments:
  plugin                Plugin

optional arguments:
  --metadata-dump       **For internal testing only** Dump json metadata for all plugins.
  --playbook-dir BASEDIR
                        Since this tool does not use playbooks, use this as a substitute playbook directory.This sets the relative path for many features
                        including roles/ group_vars/ etc.
  --version             show program's version number, config file location, configured module search path, module location, executable location and exit
  -F, --list_files      Show plugin names and their source files without summaries (implies --list). A supplied argument will be used for filtering, can
                        be a namespace or full collection name.
  -M MODULE_PATH, --module-path MODULE_PATH
                        prepend colon-separated path(s) to module library (default=~/.ansible/plugins/modules:/usr/share/ansible/plugins/modules)
  -e ENTRY_POINT, --entry-point ENTRY_POINT
                        Select the entry point for role(s).
  -h, --help            show this help message and exit
  -j, --json            Change output into json format.
  -l, --list            List available plugins. A supplied argument will be used for filtering, can be a namespace or full collection name.
  -r ROLES_PATH, --roles-path ROLES_PATH
                        The path to the directory containing your roles.
  -s, --snippet         Show playbook snippet for these plugin types: inventory, lookup, module
  -t {become,cache,callback,cliconf,connection,httpapi,inventory,lookup,netconf,shell,vars,module,strategy,role,keyword}, --type {become,cache,callback,cliconf,connection,httpapi,inventory,lookup,netconf,shell,vars,module,strategy,role,keyword}
                        Choose which plugin type (defaults to "module"). Available plugin types are : ('become', 'cache', 'callback', 'cliconf',
                        'connection', 'httpapi', 'inventory', 'lookup', 'netconf', 'shell', 'vars', 'module', 'strategy', 'role', 'keyword')
  -v, --verbose         verbose mode (-vvv for more, -vvvv to enable connection debugging)

See man pages for Ansible CLI options or website for tutorials https://docs.ansible.com

모듈 목록 확인

ansible-doc -l

ansible ping 모듈

ansible-doc ping
ansible-doc -s ping

ansible shell 모듈

ansible-doc -l | grep shell
$ ansible-doc -l | grep shell
shell               Execute shell commands on targets
vmware_vm_shell     Run commands in a VMware guest operating system
win_shell           Execute shell commands on target hosts
ansible-doc -s shell
$ ansible-doc -s shell       
- name: Execute shell commands on targets
  shell:
      chdir:                 # Change into this directory before running the command.
      cmd:                   # The command to run followed by optional arguments.
      creates:               # A filename, when it already exists, this step will *not* be run.
      executable:            # Change the shell used to execute the command. This expects an absolute path to the executable.
      free_form:             # The shell module takes a free form command to run, as a string. There is no actual parameter named 'free form'. See the examples
                               on how to use this module.
      removes:               # A filename, when it does not exist, this step will *not* be run.
      stdin:                 # Set the stdin of the command directly to the specified value.
      stdin_add_newline:     # Whether to append a newline to stdin data.
      warn:                  # Whether to enable task warnings.
ansible-doc shell
$ ansible-doc shell
> SHELL    (/usr/lib/python2.7/site-packages/ansible/modules/commands/shell.py)

        The `shell' module takes the command name followed by a list of space-delimited arguments. Either a free form command or
        `cmd' parameter is required, see the examples. It is almost exactly like the [command] module but runs the command
        through a shell (`/bin/sh') on the remote node. For Windows targets, use the [win_shell] module instead.

  * This module is maintained by The Ansible Core Team
  * note: This module has a corresponding action plugin.

OPTIONS (= is mandatory):

- chdir
        Change into this directory before running the command.
        [Default: (null)]
        type: path
        version_added: 0.6

- cmd
        The command to run followed by optional arguments.
        [Default: (null)]
        type: str

- creates
        A filename, when it already exists, this step will *not* be run.
        [Default: (null)]
        type: path

- executable
        Change the shell used to execute the command.
        This expects an absolute path to the executable.
        [Default: (null)]
        type: path
        version_added: 0.9

- free_form
        The shell module takes a free form command to run, as a string.
        There is no actual parameter named 'free form'.
        See the examples on how to use this module.
        [Default: (null)]
        type: str

- removes
        A filename, when it does not exist, this step will *not* be run.
        [Default: (null)]
        type: path
        version_added: 0.8

- stdin
        Set the stdin of the command directly to the specified value.
        [Default: (null)]
        type: str
        version_added: 2.4

- stdin_add_newline
        Whether to append a newline to stdin data.
        [Default: True]
        type: bool
        version_added: 2.8

- warn
        Whether to enable task warnings.
        [Default: True]
        type: bool
        version_added: 1.8


NOTES:
      * If you want to execute a command securely and predictably, it may be better to use the [command] module instead.
        Best practices when writing playbooks will follow the trend of using [command] unless the `shell' module is
        explicitly required. When running ad-hoc commands, use your best judgement.
      * Check mode is supported when passing `creates' or `removes'. If running in check mode and either of these are
        specified, the module will check for the existence of the file and report the correct changed status. If these are
        not supplied, the task will be skipped.
      * To sanitize any variables passed to the shell module, you should use `{{ var | quote }}' instead of just `{{ var
        }}' to make sure they do not include evil things like semicolons.
      * An alternative to using inline shell scripts with this module is to use the [script] module possibly together with
        the [template] module.
      * For rebooting systems, use the [reboot] or [win_reboot] module.


SEE ALSO:
      * Module command
           The official documentation on the command module.
           https://docs.ansible.com/ansible/2.9/modules/command_module.html
      * Module raw
           The official documentation on the raw module.
           https://docs.ansible.com/ansible/2.9/modules/raw_module.html
      * Module script
           The official documentation on the script module.
           https://docs.ansible.com/ansible/2.9/modules/script_module.html
      * Module win_shell
           The official documentation on the win_shell module.
           https://docs.ansible.com/ansible/2.9/modules/win_shell_module.html


AUTHOR: Ansible Core Team, Michael DeHaan
        METADATA:
          status:
          - stableinterface
          supported_by: core
        

EXAMPLES:

- name: Execute the command in remote shell; stdout goes to the specified file on the remote.
  shell: somescript.sh >> somelog.txt

- name: Change the working directory to somedir/ before executing the command.
  shell: somescript.sh >> somelog.txt
  args:
    chdir: somedir/

# You can also use the 'args' form to provide the options.
- name: This command will change the working directory to somedir/ and will only run when somedir/somelog.txt doesn't exist.
  shell: somescript.sh >> somelog.txt
  args:
    chdir: somedir/
    creates: somelog.txt

# You can also use the 'cmd' parameter instead of free form format.
- name: This command will change the working directory to somedir/.
  shell:
    cmd: ls -l | grep log
    chdir: somedir/

- name: Run a command that uses non-posix shell-isms (in this example /bin/sh doesn't handle redirection and wildcards together but bash does)
  shell: cat < /tmp/*txt
  args:
    executable: /bin/bash

- name: Run a command using a templated variable (always use quote filter to avoid injection)
  shell: cat {{ myfile|quote }}

# You can use shell to run other executables to perform actions inline
- name: Run expect to wait for a successful PXE boot via out-of-band CIMC
  shell: |
    set timeout 300
    spawn ssh admin@{{ cimc_host }}

    expect "password:"
    send "{{ cimc_password }}\n"

    expect "\n{{ cimc_name }}"
    send "connect host\n"

    expect "pxeboot.n12"
    send "\n"

    exit 0
  args:
    executable: /usr/bin/expect
  delegate_to: localhost

# Disabling warnings
- name: Using curl to connect to a host via SOCKS proxy (unsupported in uri). Ordinarily this would throw a warning.
  shell: curl --socks5 localhost:9000 http://www.ansible.com
  args:
    warn: no


RETURN VALUES:

msg:
    description: changed
    returned: always
    type: bool
    sample: True
start:
    description: The command execution start time
    returned: always
    type: str
    sample: '2016-02-25 09:18:26.429568'
end:
    description: The command execution end time
    returned: always
    type: str
    sample: '2016-02-25 09:18:26.755339'
delta:
    description: The command execution delta time
    returned: always
    type: str
    sample: '0:00:00.325771'
stdout:
    description: The command standard output
    returned: always
    type: str
    sample: 'Clustering node rabbit@slave1 with rabbit@master ...'
stderr:
    description: The command standard error
    returned: always
    type: str
    sample: 'ls: cannot access foo: No such file or directory'
cmd:
    description: The command executed by the task
    returned: always
    type: str
    sample: 'rabbitmqctl join_cluster rabbit@master'
rc:
    description: The command return code (0 means success)
    returned: always
    type: int
    sample: 0
stdout_lines:
    description: The command standard output split in lines
    returned: always
    type: list
    sample: [u'Clustering node rabbit@slave1 with rabbit@master ...']

모든 모듈 및 플러그인의 인덱스

 

참고URL

- Index of all Modules(Ansible) : https://docs.ansible.com/ansible/latest/collections/index_module.html

- Index of all Modules(Ansible) : https://docs.ansible.com/ansible/2.9/modules/list_of_all_modules.html

 

728x90
반응형