1. 程式人生 > 其它 >Ansible入門系列--模組

Ansible入門系列--模組

一、Ansible常用模組

1、Command

在遠端主機執行命令,預設模組,可忽略-m選項。


[root@ansible ~]# ansible-doc -s command
- name: Execute commands on targets
  command:
      argv:                  # Passes the command as a list rather than a string. Use `argv' to avoid quoting values that would otherwise be interpreted incorrectly (for example "user name"). Only the string or the list form can be
                               provided, not both.  One or the other must be provided.
      chdir:                 # Change into this directory before running the command.
      cmd:                   # The command to run.
      creates:               # A filename or (since 2.0) glob pattern. If it already exists, this step *won't* be run.
      free_form:             # The command module takes a free form command to run. There is no actual parameter named 'free form'.
      removes:               # A filename or (since 2.0) glob pattern. If it already exists, this step *will* be run.
      stdin:                 # Set the stdin of the command directly to the specified value.
      stdin_add_newline:     # If set to `yes', append a newline to stdin data.
      strip_empty_ends:      # Strip empty lines from the end of stdout/stderr in result.
      warn:                  # Enable or disable task warnings.
[root@ansible ~]# 

  

此命令不支援 $VARNAME < > | ; & 等,shell模組實現
chdir:   進入到被管理主機目錄
creates: 如果有一個目錄是存在的,步驟將不會執行Command命令
ansible all -a "chdir=/var/log ls -al"