CentOS 7.3 下 Ansible 学习

机器资源

主机名IP地址角色
master192.168.27.110控制机器
slave1192.168.27.111被控制机器1
slave2192.168.27.112被控制机器2

Ansible 安装

控制机器
  • epel 源安装
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  • ansible 安装
yum -y install ansible
  • 防火墙关闭
systemctl stop firewalld
systemctl disable firewalld
  • 添加被控制主机
vim /etc/ansible/hosts
  [slave1]
  192.168.27.111
  [slave2]
  192.168.27.112
  • 通过ssh实现控制主机与被控制主机连接
ssh-keygen -t rsa //一路回车,生成公钥
ssh-copy-id root@192.168.27.111 // 将生成的公钥发送给个被控制主机【需要输入被控制主机的密码】
ssh-copy-id root@192.168.27.112 
被控制机器
  • 防火墙关闭
systemctl stop firewalld
systemctl disable firewalld
  • 接收控制主机发送的公钥
ssh-agent bash
ssh-add

Ansible 配置完成测试

ansible all -a 'date'  //查看两台被管理主机的时间

192.168.27.112 | SUCCESS | rc=0 >>
Tue Sep  4 14:52:57 CST 2018

192.168.27.111 | SUCCESS | rc=0 >>
Tue Sep  4 14:52:58 CST 2018

Ansible 应用命令模块

Ansible 命令格式
  • 命令格式
ansible [主机][-m 模块][-a 模块参数]
ansible-doc -l // 列出所有已安装的模块
ansible-doc -s user // -s 列出模块描述信息和操作动作
  • 示例
[root@master ansible]# ansible-doc -s command
- name: Executes a command on a remote node
  command:
      argv:                  # Allows the user to provide the command as a list vs. a string.  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.
      creates:               # A filename or (since 2.0) glob pattern, when it already exists, this step will *not* be run.
      free_form:             # (required) The command module takes a free form command to run.  There is no parameter actually named 'free form'. See the examples!
      removes:               # A filename or (since 2.0) glob pattern, when it does not exist, this step will *not* be run.
      stdin:                 # Set the stdin of the command directly to the specified value.
      warn:                  # If command_warnings are on in ansible.cfg, do not warn about this particular line if set to `no'.
command 模块
  • help
[root@master ~]# ansible-doc -s command
- name: Executes a command on a remote node
  command:
      argv:                  # Allows the user to provide the command as a list vs. a string.  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.
      creates:               # A filename or (since 2.0) glob pattern, when it already exists, this step will *not* be run.
      free_form:             # (required) The command module takes a free form command to run.  There is no parameter actually named 'free form'. See the examples!
      removes:               # A filename or (since 2.0) glob pattern, when it does not exist, this step will *not* be run.
      stdin:                 # Set the stdin of the command directly to the specified value.
      warn:                  # If command_warnings are on in ansible.cfg, do not warn about this particular line if set to `no'.
  • ansible 管理工具默认模块,若省略“-m command”,ansible默认使用command模块
[root@master ~]# ansible 192.168.27.111 -m command -a 'date' // 指定ip执行date
192.168.27.111 | SUCCESS | rc=0 >>
Wed Sep  5 19:01:47 CST 2018

[root@master ~]# ansible slave1 -m command -a 'date' // 指定分类执行date
192.168.27.111 | SUCCESS | rc=0 >>
Wed Sep  5 19:02:28 CST 2018

[root@master ~]# ansible all -m command -a 'date' // 所有host主机执行date命令
192.168.27.112 | SUCCESS | rc=0 >>
Wed Sep  5 19:21:47 CST 2018

192.168.27.111 | SUCCESS | rc=0 >>
Wed Sep  5 19:21:47 CST 2018

[root@master ~]# ansible all -a 'date' // 如果不加 “-m 模块”,则默认运行command模块
192.168.27.111 | SUCCESS | rc=0 >>
Wed Sep  5 19:22:55 CST 2018

192.168.27.112 | SUCCESS | rc=0 >>
Wed Sep  5 19:22:54 CST 2018
cron 模块
自定义计划任务模块,用于管理被管理主机的任务计划。
cron有两种状态(state):
    present:表示添加(可以省略)
    absent:表示移除
  • help
[root@master ~]# ansible-doc -s cron
- name: Manage cron.d and crontab entries
  cron:
      backup:                # If set, create a backup of the crontab before it is modified. The location of the backup is returned in the `backup_file' variable by this module.
      cron_file:             # If specified, uses this file instead of an individual user's crontab. If this is a relative path, it is interpreted with respect to /etc/cron.d. (If it is
                               absolute, it will typically be /etc/crontab). Many linux distros expect (and some require) the filename portion to consist
                               solely of upper- and lower-case letters, digits, underscores, and hyphens. To use the `cron_file' parameter you must specify
                               the `user' as well.
      day:                   # Day of the month the job should run ( 1-31, *, */2, etc )
      disabled:              # If the job should be disabled (commented out) in the crontab. Only has effect if `state=present'.
      env:                   # If set, manages a crontab's environment variable. New variables are added on top of crontab. "name" and "value" parameters are the name and the value of
                               environment variable.
      hour:                  # Hour when the job should run ( 0-23, *, */2, etc )
      insertafter:           # Used with `state=present' and `env'. If specified, the environment variable will be inserted after the declaration of specified environment variable.
      insertbefore:          # Used with `state=present' and `env'. If specified, the environment variable will be inserted before the declaration of specified environment variable.
      job:                   # The command to execute or, if env is set, the value of environment variable. The command should not contain line breaks. Required if state=present.
      minute:                # Minute when the job should run ( 0-59, *, */2, etc )
      month:                 # Month of the year the job should run ( 1-12, *, */2, etc )
      name:                  # Description of a crontab entry or, if env is set, the name of environment variable. Required if state=absent. Note that if name is not set and state=present,
                               then a new crontab entry will always be created, regardless of existing ones.
      reboot:                # If the job should be run at reboot. This option is deprecated. Users should use special_time.
      special_time:          # Special time specification nickname.
      state:                 # Whether to ensure the job or environment variable is present or absent.
      user:                  # The specific user whose crontab should be modified.
      weekday:               # Day of the week that the job should run ( 0-6 for Sunday-Saturday, *, etc )
  • 添加计划任务
ansible slave1 -m cron -a 'minute="*/1" job="/bin/echo test" name="test cron job"' // 每分钟执行一次
  • 移除任务计划【通过“任务计划名称”进行移除,如果任务没有取名字,使用“name=none”即可】
ansible slave1 -m cron -a 'name="test cron job" state=absent'
user 模块【用于用户的创建、更改、删除等操作,用name指定闯将用户的名称】
  • help
[root@master ~]# ansible-doc -s user
- name: Manage user accounts
  user:
      append:                # If `yes', add the user to the groups specified in `groups'. If `no', user will only be added to the groups specified in `groups', removing them from all
                               other groups.
      comment:               # Optionally sets the description (aka `GECOS') of user account.
      create_home:           # Unless set to `no', a home directory will be made for the user when the account is created or if the home directory does not exist. Changed from `createhome'
                               to `create_home' in version 2.5.
      expires:               # An expiry time for the user in epoch, it will be ignored on platforms that do not support this. Currently supported on GNU/Linux, FreeBSD, and DragonFlyBSD.
                               Since version 2.6 you can remove the expiry time specify a negative value. Currently supported on GNU/Linux and FreeBSD.
      force:                 # This only affects `state=absent', it forces removal of the user and associated directories on supported platforms. The behavior is the same as `userdel
                               --force', check the man page for `userdel' on your system for details and support.
      generate_ssh_key:      # Whether to generate a SSH key for the user in question. This will *not* overwrite an existing SSH key.
      group:                 # Optionally sets the user's primary group (takes a group name).
      groups:                # List of groups user will be added to. When set to an empty string `''', `null', or `~', the user is removed from all groups except the primary group. (`~'
                               means `null' in YAML) Before version 2.3, the only input format allowed was a comma separated string. Now this parameter
                               accepts a list as well as a comma separated string.
      hidden:                # Darwin/OS X only, optionally hide the user from the login window and system preferences. The default will be 'True' if the `system' option is used.
      home:                  # Optionally set the user's home directory.
      local:                 # Forces the use of "local" command alternatives on platforms that implement it. This is useful in environments that use centralized authentification when you
                               want to manipulate the local users. I.E. it uses `luseradd` instead of `useradd`. This requires that these commands exist on
                               the targeted host, otherwise it will be a fatal error.
      login_class:           # Optionally sets the user's login class, a feature of most BSD OSs.
      move_home:             # If set to `yes' when used with `home=', attempt to move the user's old home directory to the specified directory if it isn't there already and the old home
                               exists.
      name:                  # (required) Name of the user to create, remove or modify.
      non_unique:            # Optionally when used with the -u option, this option allows to change the user ID to a non-unique value.
      password:              # Optionally set the user's password to this crypted value. On Darwin/OS X systems, this value has to be cleartext. Beware of security issues. See
                               https://docs.ansible.com/ansible/faq.html#how-do-i-generate-crypted-passwords-for-the-user-module for details on various ways
                               to generate these password values.
      password_lock:         # Lock the password (usermod -L, pw lock, usermod -C). BUT implementation differs on different platforms, this option does not always mean the user cannot
                               login via other methods. This option does not disable the user, only lock the password. Do not change the password in the same
                               task. Currently supported on Linux, FreeBSD, DragonFlyBSD, NetBSD.
      remove:                # This only affects `state=absent', it attempts to remove directories associated with the user. The behavior is the same as `userdel --remove', check the man
                               page for details and support.
      seuser:                # Optionally sets the seuser type (user_u) on selinux enabled systems.
      shell:                 # Optionally set the user's shell. On Mac OS X, before version 2.5, the default shell for non-system users was /usr/bin/false. Since 2.5, the default shell for
                               non-system users on Mac OS X is /bin/bash.
      skeleton:              # Optionally set a home skeleton directory. Requires create_home option!
      ssh_key_bits:          # Optionally specify number of bits in SSH key to create.
      ssh_key_comment:       # Optionally define the comment for the SSH key.
      ssh_key_file:          # Optionally specify the SSH key filename. If this is a relative filename then it will be relative to the user's home directory.
      ssh_key_passphrase:    # Set a passphrase for the SSH key.  If no passphrase is provided, the SSH key will default to having no passphrase.
      ssh_key_type:          # Optionally specify the type of SSH key to generate. Available SSH key types will depend on implementation present on target host.
      state:                 # Whether the account should exist or not, taking action if the state is different from what is stated.
      system:                # When creating an account `state=present', setting this to `yes' makes the user a system account. This setting cannot be changed on existing users.
      uid:                   # Optionally sets the `UID' of the user.
      update_password:       # `always' will update passwords if they differ.  `on_create' will only set the password for newly created users.
  • 创建用户
[root@master ~]# ansible slave1 -m user -a 'name=testansi' // 创建testansi用户,参数默认
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "comment": "", 
    "create_home": true, 
    "group": 1000, 
    "home": "/home/testansi", 
    "name": "testansi", 
    "shell": "/bin/bash", 
    "state": "present", 
    "system": false, 
    "uid": 1000
}
[root@master ~]# ansible slave1 -m user -a 'state=present name=testansi1 shell=/sbin/nologin home=/home/testansi1'
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "comment": "", 
    "create_home": true, 
    "group": 1001, 
    "home": "/home/testansi1", 
    "name": "testansi1", 
    "shell": "/sbin/nologin", 
    "state": "present", 
    "system": false, 
    "uid": 1001
}

state=present // 添加用户
name=testansi1 // 用户名
shell=/sbin/nologin // 用户shell
home=/home/testansi1 // 用户家目录

[root@master ~]# ansible slave1 -m user -a 'name=slave11 uid=1010 system=yes group=slave1' // 利用组创建用户
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "comment": "", 
    "create_home": true, 
    "group": 1000, 
    "home": "/home/slave11", 
    "name": "slave11", 
    "shell": "/bin/bash", 
    "state": "present", 
    "system": true, 
    "uid": 1010
}

name=slave11 // 创建用户名
uid=1010 // 用户id
system=yes // 系统用户
group=slave1 // 指定用户组
  • 查看用户是否创建成功
[root@master ~]# ansible slave1 -a "tail -2 /etc/passwd" // 查看“/etc/passwd最后两行”
192.168.27.111 | SUCCESS | rc=0 >>
testansi:x:1000:1000::/home/testansi:/bin/bash
testansi1:x:1001:1001::/home/testansi1:/sbin/nologin 
slave11:x:1010:1000::/home/slave11:/bin/bash 【指定组创建用户】
  • 删除用户
[root@master ~]# ansible slave1 -m user -a 'name=testansi state=absent remove=yes'
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "force": false, 
    "name": "testansi", 
    "remove": true, 
    "state": "absent"
}
[root@master ~]# ansible slave1 -m user -a 'name=testansi1 state=absent remove=yes'
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "force": false, 
    "name": "testansi1", 
    "remove": true, 
    "state": "absent"
}

state=absent // 表示删除用户
remove=yes // 删除用户同时删除用户家目录
  • 查看用户是否删除成功
[root@master ~]# ansible slave1 -a "tail -2 /etc/passwd"
192.168.27.111 | SUCCESS | rc=0 >>
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin


[root@master ~]# ansible slave1 -a "ls -l /home"
192.168.27.111 | SUCCESS | rc=0 >>
total 0
group 模块【针对用户的组进行管理】
  • help
[root@master ~]# ansible-doc -s group
- name: Add or remove groups
  group:
      gid:                   # Optional `GID' to set for the group.
      local:                 # Forces the use of "local" command alternatives on platforms that implement it. This is useful in environments that use centralized authentification when you
                               want to manipulate the local groups. I.E. it uses `lgroupadd` instead of `useradd`. This requires that these commands exist on
                               the targeted host, otherwise it will be a fatal error.
      name:                  # (required) Name of the group to manage.
      state:                 # Whether the group should be present or not on the remote host.
      system:                # If `yes', indicates that the group created is a system group.
  • 创建用户组
[root@master ~]# ansible slave1 -m group -a 'name=slave1' // 添加默认组账号
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "gid": 1000, 
    "name": "slave1", 
    "state": "present", 
    "system": false
}
[root@master ~]# ansible slave1 -m group -a 'name=slave11 gid=1010 system=yes' // 按照要求创建
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "gid": 1010, 
    "name": "slave11", 
    "state": "present", 
    "system": true
}

name=slave1 // 创建组名称
gid=1010 // 创建组id
system=yes // 设置为系统组
state=present // 状态为创建
  • 查看用户组是否创建成功
[root@master ~]# ansible slave1 -a 'tail -2 /etc/group' // 查看slave1机器上面信息
192.168.27.111 | SUCCESS | rc=0 >>
slave1:x:1000: // 默认添加组
slave11:x:1010: // 指定添加组

[root@master ~]# ansible slave1 -a 'id slave11'
192.168.27.111 | SUCCESS | rc=0 >>
uid=1010(slave11) gid=1000(slave1) groups=1000(slave1)
  • 删除用户组
[root@master ~]# ansible slave1 -m group -a 'name=slave1  state=absent'
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "name": "slave1", 
    "state": "absent"
}
[root@master ~]# ansible slave1 -m group -a 'name=slave11  state=absent'
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "name": "slave11", 
    "state": "absent"
}
[root@master ~]# ansible slave1 -m group -a 'name=slave1 gid=1000 state=absent' // 当组内有用户时会报错
192.168.27.111 | FAILED! => {
    "changed": false, 
    "msg": "groupdel: cannot remove the primary group of user 'slave11'\n", 
    "name": "slave1"
}

name=slave1 // 组名称
gid=1000 // 组id
state=absent // 状态为删除
  • 查看用户是否删除成功
[root@master ~]# ansible slave1 -a 'tail -2 /etc/group'
192.168.27.111 | SUCCESS | rc=0 >>
postfix:x:89:
sshd:x:74:
copy 模块【用于实现文件复制和批量文件下发】
  • help
[root@master ~]# ansible-doc -s copy
- name: Copies files to remote locations
  copy:
      attributes:            # Attributes the file or directory should have. To get supported flags look at the man page for `chattr' on the target system. This string should contain the
                               attributes in the same order as the one displayed by `lsattr'.
      backup:                # Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
      checksum:              # SHA1 checksum of the file being transferred. Used to validate that the copy of the file was successful. If this is not provided, ansible will use the local
                               calculated checksum of the src file.
      content:               # When used instead of `src', sets the contents of a file directly to the specified value. For anything advanced or with formatting also look at the template
                               module.
      decrypt:               # This option controls the autodecryption of source files using vault.
      dest:                  # (required) Remote absolute path where the file should be copied to. If `src' is a directory, this must be a directory too. If `dest' is a nonexistent path
                               and if either `dest' ends with "/" or `src' is a directory, `dest' is created. If `src' and `dest' are files, the parent
                               directory of `dest' isn't created: the task fails if it doesn't already exist.
      directory_mode:        # When doing a recursive copy set the mode for the directories. If this is not set we will use the system defaults. The mode is only set on directories which
                               are newly created, and will not affect those that already existed.
      follow:                # This flag indicates that filesystem links in the destination, if they exist, should be followed.
      force:                 # the default is `yes', which will replace the remote file when contents are different than the source. If `no', the file will only be transferred if the
                               destination does not exist.
      group:                 # Name of the group that should own the file/directory, as would be fed to `chown'.
      local_follow:          # This flag indicates that filesystem links in the source tree, if they exist, should be followed.
      mode:                  # Mode the file or directory should be. For those used to `/usr/bin/chmod' remember that modes are actually octal numbers.  You must either specify the leading
                               zero so that Ansible's YAML parser knows it is an octal number (like `0644' or `01777') or quote it (like `'644'' or `'0644''
                               so Ansible receives a string and can do its own conversion from string into number.  Giving Ansible a number without following
                               one of these rules will end up with a decimal number which will have unexpected results.  As of version 1.8, the mode may be
                               specified as a symbolic mode (for example, `u+rwx' or `u=rw,g=r,o=r').  As of version 2.3, the mode may also be the special
                               string `preserve'.  `preserve' means that the file will be given the same permissions as the source file.
      owner:                 # Name of the user that should own the file/directory, as would be fed to `chown'.
      remote_src:            # If `no', it will search for `src' at originating/master machine. If `yes' it will go to the remote/target machine for the `src'. Default is `no'. Currently
                               `remote_src' does not support recursive copying. `remote_src' only works with `mode=preserve' as of version 2.6.
      selevel:               # Level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the `range'. `_default' feature works as for `seuser'.
      serole:                # Role part of SELinux file context, `_default' feature works as for `seuser'.
      setype:                # Type part of SELinux file context, `_default' feature works as for `seuser'.
      seuser:                # User part of SELinux file context. Will default to system policy, if applicable. If set to `_default', it will use the `user' portion of the policy if
                               available.
      src:                   # Local path to a file to copy to the remote server; can be absolute or relative. If path is a directory, it is copied recursively. In this case, if path ends
                               with "/", only inside contents of that directory are copied to destination. Otherwise, if it does not end with "/", the
                               directory itself with all contents is copied. This behavior is similar to Rsync.
      unsafe_writes:         # Normally this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, sometimes systems are configured or just
                               broken in ways that prevent this. One example are docker mounted files, they cannot be updated atomically and can only be done
                               in an unsafe manner. This boolean option allows ansible to fall back to unsafe methods of updating files for those cases in
                               which you do not have any other choice. Be aware that this is subject to race conditions and can lead to data corruption.
      validate:              # The validation command to run before copying into place. The path to the file to validate is passed in via '%s' which must be present as in the example
                               below. The command is passed securely so shell features like expansion and pipes won't work.
  • 创建用户和组
[root@master ~]# ansible slave1 -m group -a 'name=slave1'
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "gid": 1000, 
    "name": "slave1", 
    "state": "present", 
    "system": false
}
[root@master ~]# ansible slave1 -m user -a 'name=slave1 group=slave1'
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "comment": "", 
    "create_home": true, 
    "group": 1000, 
    "home": "/home/slave1", 
    "name": "slave1", 
    "shell": "/bin/bash", 
    "state": "present", 
    "system": false, 
    "uid": 1000
}

[root@master ~]# ansible slave1 -a 'tail -2 /etc/group'
192.168.27.111 | SUCCESS | rc=0 >>
sshd:x:74:
slave1:x:1000:

[root@master ~]# ansible slave1 -a 'tail -2 /etc/passwd'
192.168.27.111 | SUCCESS | rc=0 >>
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
slave1:x:1000:1000::/home/slave1:/bin/bash
  • 使用创建的用户和组实现“新建文件并下发”
[root@master ~]# ansible slave1 -m copy -a 'dest=/root/test.txt content="test copy" owner=slave1 group=slave1 mode=600'
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "checksum": "bf30ec265d6e71a0ca390321c62ca2e875032282", 
    "dest": "/root/test.txt", 
    "gid": 1000, 
    "group": "slave1", 
    "md5sum": "8a51b93bf77f1373a33fc46c1b774f82", 
    "mode": "0600", 
    "owner": "slave1", 
    "secontext": "system_u:object_r:admin_home_t:s0", 
    "size": 9, 
    "src": "/root/.ansible/tmp/ansible-tmp-1536167144.88-280237295062076/source", 
    "state": "file", 
    "uid": 1000
}

dest=/root/test.txt content="test copy" owner=slave1 group=slave1 mode=600
  • 使用创建的用户和组实现“现有文件下发”
[root@master ~]# ansible slave1 -m copy -a 'src=/root/test_copy.txt dest=/root/ owner=slave1 group=slave1 mode=640'
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709", 
    "dest": "/root/test_copy.txt", 
    "gid": 1000, 
    "group": "slave1", 
    "md5sum": "d41d8cd98f00b204e9800998ecf8427e", 
    "mode": "0640", 
    "owner": "slave1", 
    "secontext": "system_u:object_r:admin_home_t:s0", 
    "size": 0, 
    "src": "/root/.ansible/tmp/ansible-tmp-1536167363.95-38767429742559/source", 
    "state": "file", 
    "uid": 1000
}

src=/root/test_copy.txt // 源文件
dest=/root/ // 目标地址
owner=slave1 // 所属者
group=slave1 // 所属组
mode=640 // 文件权限
  • 验证下发文件
[root@master ~]# ansible slave1 -a 'ls -l /root' // 查看目录下文件 + 文件权限
192.168.27.111 | SUCCESS | rc=0 >>
total 8
-rw-------. 1 root   root   1609 Sep  5 00:19 anaconda-ks.cfg
-rw-r-----. 1 slave1 slave1    0 Sep  6 01:09 test_copy.txt
-rw-------. 1 slave1 slave1    9 Sep  6 01:05 test.txt

[root@master ~]# ansible slave1 -a 'cat /root/test.txt' // 验证文件中内容
192.168.27.111 | SUCCESS | rc=0 >>
test copy
file 模块【设置文件属性】
  • help
[root@master ~]# ansible-doc -s file
- name: Sets attributes of files
  file:
      attributes:            # Attributes the file or directory should have. To get supported flags look at the man page for `chattr' on the target system. This string should contain the
                               attributes in the same order as the one displayed by `lsattr'.
      follow:                # This flag indicates that filesystem links, if they exist, should be followed. Previous to Ansible 2.5, this was `no' by default.
      force:                 # force the creation of the symlinks in two cases: the source file does not exist (but will appear later); the destination exists and is a file (so, we need to
                               unlink the "path" file and create symlink to the "src" file in place of it).
      group:                 # Name of the group that should own the file/directory, as would be fed to `chown'.
      mode:                  # Mode the file or directory should be. For those used to `/usr/bin/chmod' remember that modes are actually octal numbers. You must either specify the leading
                               zero so that Ansible's YAML parser knows it is an octal number (like `0644' or `01777') or quote it (like `'644'' or `'0644''
                               so Ansible receives a string and can do its own conversion from string into number.  Giving Ansible a number without following
                               one of these rules will end up with a decimal number which will have unexpected results. As of version 1.8, the mode may be
                               specified as a symbolic mode (for example, `u+rwx' or `u=rw,g=r,o=r').
      owner:                 # Name of the user that should own the file/directory, as would be fed to `chown'.
      path:                  # (required) path to the file being managed.  Aliases: `dest', `name'
      recurse:               # recursively set the specified file attributes (applies only to directories)
      selevel:               # Level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the `range'. `_default' feature works as for `seuser'.
      serole:                # Role part of SELinux file context, `_default' feature works as for `seuser'.
      setype:                # Type part of SELinux file context, `_default' feature works as for `seuser'.
      seuser:                # User part of SELinux file context. Will default to system policy, if applicable. If set to `_default', it will use the `user' portion of the policy if
                               available.
      src:                   # path of the file to link to (applies only to `state=link' and `state=hard'). Will accept absolute, relative and nonexisting paths. Relative paths are
                               relative to the file being created (`path') which is how the UNIX command `ln -s SRC DEST' treats relative paths.
      state:                 # If `directory', all intermediate subdirectories will be created if they do not exist. Since Ansible 1.7 they will be created with the supplied permissions.
                               If `file', the file will NOT be created if it does not exist; see the `touch' value or the [copy] or [template] module if you
                               want that behavior.  If `link', the symbolic link will be created or changed. Use `hard' for hardlinks. If `absent',
                               directories will be recursively deleted, and files or symlinks will be unlinked. Note that `absent' will not cause `file' to
                               fail if the `path' does not exist as the state did not change. If `touch' (new in 1.4), an empty file will be created if the
                               `path' does not exist, while an existing file or directory will receive updated file access and modification times (similar to
                               the way `touch` works from the command line).
      unsafe_writes:         # Normally this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, sometimes systems are configured or just
                               broken in ways that prevent this. One example are docker mounted files, they cannot be updated atomically and can only be done
                               in an unsafe manner. This boolean option allows ansible to fall back to unsafe methods of updating files for those cases in
                               which you do not have any other choice. Be aware that this is subject to race conditions and can lead to data corruption.
  • 更改文件的属主属组
[root@master ~]# ansible slave1 -m file -a 'owner=root group=root mode=755 path=/root/test.txt'
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "gid": 0, 
    "group": "root", 
    "mode": "0755", 
    "owner": "root", 
    "path": "/root/test.txt", 
    "secontext": "system_u:object_r:admin_home_t:s0", 
    "size": 9, 
    "state": "file", 
    "uid": 0
}

owner=root // 更改属主
group=root // 更改属组
mode=755 // 更改权限
path=/root/test.txt // 被更改文件
ping 模块
  • help
[root@master ~]# ansible-doc -s ping
- name: Try to connect to host, verify a usable python and return `pong' on success
  ping:
      data:                  # Data to return for the `ping' return value. If this parameter is set to `crash', the module will cause an exception.
  • 测试ping
[root@master ~]# ansible all -m ping
192.168.27.111 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
192.168.27.112 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
yum 模块【负责再被管理机器上面安装卸载软件包】
  • help
[root@master ~]# ansible-doc -s yum
- name: Manages packages with the `yum' package manager
  yum:
      allow_downgrade:       # Specify if the named package and version is allowed to downgrade a maybe already installed higher version of that package. Note that setting
                               allow_downgrade=True can make this module behave in a non-idempotent way. The task could end up with a set of packages that
                               does not match the complete list of specified packages to install (because dependencies between the downgraded package and
                               others can cause changes to the packages which were in the earlier transaction).
      bugfix:                # If set to `yes', and `state=latest' then only installs updates that have been marked bugfix related.
      conf_file:             # The remote yum configuration file to use for the transaction.
      disable_gpg_check:     # Whether to disable the GPG checking of signatures of packages being installed. Has an effect only if state is `present' or `latest'.
      disable_plugin:        # `Plugin' name to disable for the install/update operation. The disabled plugins will not persist beyond the transaction.
      disablerepo:           # `Repoid' of repositories to disable for the install/update operation. These repos will not persist beyond the transaction. When specifying multiple repos,
                               separate them with a ",".
      enable_plugin:         # `Plugin' name to enable for the install/update operation. The enabled plugin will not persist beyond the transaction.
      enablerepo:            # `Repoid' of repositories to enable for the install/update operation. These repos will not persist beyond the transaction. When specifying multiple repos,
                               separate them with a ",".
      exclude:               # Package name(s) to exclude when state=present, or latest
      installroot:           # Specifies an alternative installroot, relative to which all packages will be installed.
      list:                  # Package name to run the equivalent of yum list <package> against. In addition to listing packages, use can also list the following: `installed', `updates',
                               `available' and `repos'.
      name:                  # A package name or package specifier with version, like `name-1.0'. If a previous version is specified, the task also needs to turn `allow_downgrade' on. See
                               the `allow_downgrade' documentation for caveats with downgrading packages. When using state=latest, this can be '*' which
                               means run `yum -y update'. You can also pass a url or a local path to a rpm file (using state=present). To operate on several
                               packages this can accept a comma separated list of packages or (as of 2.0) a list of packages.
      security:              # If set to `yes', and `state=latest' then only installs updates that have been marked security related.
      skip_broken:           # Resolve depsolve problems by removing packages that are causing problems from the trans‐ action.
      state:                 # Whether to install (`present' or `installed', `latest'), or remove (`absent' or `removed') a package. `present' and `installed' will simply ensure that a
                               desired package is installed. `latest' will update the specified package if it's not of the latest available version. `absent'
                               and `removed' will remove the specified package.
      update_cache:          # Force yum to check if cache is out of date and redownload if needed. Has an effect only if state is `present' or `latest'.
      update_only:           # When using latest, only update installed packages. Do not install packages. Has an effect only if state is `latest'
      validate_certs:        # This only applies if using a https url as the source of the rpm. e.g. for localinstall. If set to `no', the SSL certificates will not be validated. This
                               should only set to `no' used on personally controlled sites using self-signed certificates as it avoids verifying the source
                               site. Prior to 2.1 the code worked as if this was set to `yes'.
  • 检测是否已安装
[root@master ~]# ansible slave1 -m command -a 'rpm -qa vim warn=False'
192.168.27.111 | SUCCESS | rc=0 >>
[root@master ~]# ansible slave1 -m command -a 'rpm -q httpd warn=False'
192.168.27.111 | FAILED | rc=1 >>
package httpd is not installednon-zero return code
  • 安装
[root@master ~]# ansible slave1 -m yum -a 'name=vim' // 已安装测试
192.168.27.111 | SUCCESS => {
    "changed": false, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "2:vim-enhanced-7.4.160-4.el7.x86_64 providing vim is already installed"
    ]
}

[root@master ~]# ansible slave1 -m yum -a 'name=httpd' // 未安装,安装成功
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: mirror.bit.edu.cn\n * extras: mirrors.huaweicloud.com\n * updates: mirrors.huaweicloud.com\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.4.6-80.el7.centos.1 will be installed\n--> Processing Dependency: httpd-tools = 2.4.6-80.el7.centos.1 for package: httpd-2.4.6-80.el7.centos.1.x86_64\n--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-80.el7.centos.1.x86_64\n--> Running transaction check\n---> Package httpd-tools.x86_64 0:2.4.6-80.el7.centos.1 will be installed\n---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package           Arch         Version                     Repository     Size\n================================================================================\nInstalling:\n httpd             x86_64       2.4.6-80.el7.centos.1       updates       2.7 M\nInstalling for dependencies:\n httpd-tools       x86_64       2.4.6-80.el7.centos.1       updates        90 k\n mailcap           noarch       2.1.41-2.el7                base           31 k\n\nTransaction Summary\n================================================================================\nInstall  1 Package (+2 Dependent packages)\n\nTotal download size: 2.8 M\nInstalled size: 9.6 M\nDownloading packages:\n--------------------------------------------------------------------------------\nTotal                                              936 kB/s | 2.8 MB  00:03     \nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Installing : httpd-tools-2.4.6-80.el7.centos.1.x86_64                     1/3 \n  Installing : mailcap-2.1.41-2.el7.noarch                                  2/3 \n  Installing : httpd-2.4.6-80.el7.centos.1.x86_64                           3/3 \n  Verifying  : mailcap-2.1.41-2.el7.noarch                                  1/3 \n  Verifying  : httpd-tools-2.4.6-80.el7.centos.1.x86_64                     2/3 \n  Verifying  : httpd-2.4.6-80.el7.centos.1.x86_64                           3/3 \n\nInstalled:\n  httpd.x86_64 0:2.4.6-80.el7.centos.1                                          \n\nDependency Installed:\n  httpd-tools.x86_64 0:2.4.6-80.el7.centos.1    mailcap.noarch 0:2.1.41-2.el7   \n\nComplete!\n"
    ]
}
  • 卸载已安装软件包
[root@master ~]# ansible slave1 -m yum -a 'name=httpd state=absent' // 卸载httpd【state=absent】
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.4.6-80.el7.centos.1 will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package      Arch          Version                       Repository       Size\n================================================================================\nRemoving:\n httpd        x86_64        2.4.6-80.el7.centos.1         @updates        9.4 M\n\nTransaction Summary\n================================================================================\nRemove  1 Package\n\nInstalled size: 9.4 M\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Erasing    : httpd-2.4.6-80.el7.centos.1.x86_64                           1/1 \n  Verifying  : httpd-2.4.6-80.el7.centos.1.x86_64                           1/1 \n\nRemoved:\n  httpd.x86_64 0:2.4.6-80.el7.centos.1                                          \n\nComplete!\n"
    ]
}
service 模块【控制服务的运行状态】
  • help
[root@master ~]# ansible-doc -s service
- name: Manage services
  service:
      arguments:             # Additional arguments provided on the command line
      enabled:               # Whether the service should start on boot. *At least one of state and enabled are required.*
      name:                  # (required) Name of the service.
      pattern:               # If the service does not respond to the status command, name a substring to look for as would be found in the output of the `ps' command as a stand-in for a
                               status result.  If the string is found, the service will be assumed to be running.
      runlevel:              # For OpenRC init scripts (ex: Gentoo) only.  The runlevel that this service belongs to.
      sleep:                 # If the service is being `restarted' then sleep this many seconds between the stop and start command. This helps to workaround badly behaving init scripts
                               that exit immediately after signaling a process to stop.
      state:                 # `started'/`stopped' are idempotent actions that will not run commands unless necessary.  `restarted' will always bounce the service.  `reloaded' will always
                               reload. *At least one of state and enabled are required.* Note that reloaded will start the service if it is not already
                               started, even if your chosen init system wouldn't normally.
      use:                   # The service module actually uses system specific modules, normally through auto detection, this setting can force a specific module. Normally it uses the
                               value of the 'ansible_service_mgr' fact and falls back to the old 'service' module when none matching is found.
  • 查看服务状态
[root@master ~]# ansible slave1 -m command -a 'systemctl status httpd'
192.168.27.111 | FAILED | rc=3 >>
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)non-zero return code
  • 设置服务状态【设置服务状态为启动,并设置开机启动】
[root@master ~]# ansible slave1 -m service -a 'name=httpd enabled=true state=started'
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "enabled": true, 
    "name": "httpd", 
    "state": "started", 
    "status": {
        "ActiveEnterTimestampMonotonic": "0", 
        "ActiveExitTimestampMonotonic": "0", 
        "ActiveState": "inactive", 
        "After": "systemd-journald.socket remote-fs.target -.mount tmp.mount network.target nss-lookup.target basic.target system.slice", 
        "AllowIsolate": "no", 
        "AssertResult": "no", 
        "AssertTimestampMonotonic": "0", 
        "Before": "shutdown.target", 
        "BlockIOAccounting": "no", 
        "BlockIOWeight": "18446744073709551615", 
        "CPUAccounting": "no", 
        "CPUQuotaPerSecUSec": "infinity", 
        "CPUSchedulingPolicy": "0", 
        "CPUSchedulingPriority": "0", 
        "CPUSchedulingResetOnFork": "no", 
        "CPUShares": "18446744073709551615", 
        "CanIsolate": "no", 
        "CanReload": "yes", 
        "CanStart": "yes", 
        "CanStop": "yes", 
        "CapabilityBoundingSet": "18446744073709551615", 
        "ConditionResult": "no", 
        "ConditionTimestampMonotonic": "0", 
        "Conflicts": "shutdown.target", 
        "ControlPID": "0", 
        "DefaultDependencies": "yes", 
        "Delegate": "no", 
        "Description": "The Apache HTTP Server", 
        "DevicePolicy": "auto", 
        "Documentation": "man:httpd(8) man:apachectl(8)", 
        "EnvironmentFile": "/etc/sysconfig/httpd (ignore_errors=no)", 
        "ExecMainCode": "0", 
        "ExecMainExitTimestampMonotonic": "0", 
        "ExecMainPID": "0", 
        "ExecMainStartTimestampMonotonic": "0", 
        "ExecMainStatus": "0", 
        "ExecReload": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -k graceful ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "ExecStart": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -DFOREGROUND ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "ExecStop": "{ path=/bin/kill ; argv[]=/bin/kill -WINCH ${MAINPID} ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "FailureAction": "none", 
        "FileDescriptorStoreMax": "0", 
        "FragmentPath": "/usr/lib/systemd/system/httpd.service", 
        "GuessMainPID": "yes", 
        "IOScheduling": "0", 
        "Id": "httpd.service", 
        "IgnoreOnIsolate": "no", 
        "IgnoreOnSnapshot": "no", 
        "IgnoreSIGPIPE": "yes", 
        "InactiveEnterTimestampMonotonic": "0", 
        "InactiveExitTimestampMonotonic": "0", 
        "JobTimeoutAction": "none", 
        "JobTimeoutUSec": "0", 
        "KillMode": "control-group", 
        "KillSignal": "18", 
        "LimitAS": "18446744073709551615", 
        "LimitCORE": "18446744073709551615", 
        "LimitCPU": "18446744073709551615", 
        "LimitDATA": "18446744073709551615", 
        "LimitFSIZE": "18446744073709551615", 
        "LimitLOCKS": "18446744073709551615", 
        "LimitMEMLOCK": "65536", 
        "LimitMSGQUEUE": "819200", 
        "LimitNICE": "0", 
        "LimitNOFILE": "4096", 
        "LimitNPROC": "15013", 
        "LimitRSS": "18446744073709551615", 
        "LimitRTPRIO": "0", 
        "LimitRTTIME": "18446744073709551615", 
        "LimitSIGPENDING": "15013", 
        "LimitSTACK": "18446744073709551615", 
        "LoadState": "loaded", 
        "MainPID": "0", 
        "MemoryAccounting": "no", 
        "MemoryCurrent": "18446744073709551615", 
        "MemoryLimit": "18446744073709551615", 
        "MountFlags": "0", 
        "Names": "httpd.service", 
        "NeedDaemonReload": "no", 
        "Nice": "0", 
        "NoNewPrivileges": "no", 
        "NonBlocking": "no", 
        "NotifyAccess": "main", 
        "OOMScoreAdjust": "0", 
        "OnFailureJobMode": "replace", 
        "PermissionsStartOnly": "no", 
        "PrivateDevices": "no", 
        "PrivateNetwork": "no", 
        "PrivateTmp": "yes", 
        "ProtectHome": "no", 
        "ProtectSystem": "no", 
        "RefuseManualStart": "no", 
        "RefuseManualStop": "no", 
        "RemainAfterExit": "no", 
        "Requires": "basic.target -.mount", 
        "RequiresMountsFor": "/var/tmp", 
        "Restart": "no", 
        "RestartUSec": "100ms", 
        "Result": "success", 
        "RootDirectoryStartOnly": "no", 
        "RuntimeDirectoryMode": "0755", 
        "SameProcessGroup": "no", 
        "SecureBits": "0", 
        "SendSIGHUP": "no", 
        "SendSIGKILL": "yes", 
        "Slice": "system.slice", 
        "StandardError": "inherit", 
        "StandardInput": "null", 
        "StandardOutput": "journal", 
        "StartLimitAction": "none", 
        "StartLimitBurst": "5", 
        "StartLimitInterval": "10000000", 
        "StartupBlockIOWeight": "18446744073709551615", 
        "StartupCPUShares": "18446744073709551615", 
        "StatusErrno": "0", 
        "StopWhenUnneeded": "no", 
        "SubState": "dead", 
        "SyslogLevelPrefix": "yes", 
        "SyslogPriority": "30", 
        "SystemCallErrorNumber": "0", 
        "TTYReset": "no", 
        "TTYVHangup": "no", 
        "TTYVTDisallocate": "no", 
        "TimeoutStartUSec": "1min 30s", 
        "TimeoutStopUSec": "1min 30s", 
        "TimerSlackNSec": "50000", 
        "Transient": "no", 
        "Type": "notify", 
        "UMask": "0022", 
        "UnitFilePreset": "disabled", 
        "UnitFileState": "disabled", 
        "Wants": "system.slice", 
        "WatchdogTimestampMonotonic": "0", 
        "WatchdogUSec": "0"
    }
}
  • 设置服务状态【设置服务状态为停止,并关闭开机启动】
[root@master ~]# ansible slave1 -m service -a 'name=httpd enabled=false state=stopped' // 停止服务
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "enabled": false, 
    "name": "httpd", 
    "state": "stopped", 
    "status": {
        "ActiveEnterTimestamp": "Thu 2018-09-06 01:51:01 CST", 
        "ActiveEnterTimestampMonotonic": "26428646033", 
        "ActiveExitTimestampMonotonic": "0", 
        "ActiveState": "active", 
        "After": "system.slice remote-fs.target systemd-journald.socket tmp.mount basic.target nss-lookup.target -.mount network.target", 
        "AllowIsolate": "no", 
        "AssertResult": "yes", 
        "AssertTimestamp": "Thu 2018-09-06 01:51:01 CST", 
        "AssertTimestampMonotonic": "26428509554", 
        "Before": "multi-user.target shutdown.target", 
        "BlockIOAccounting": "no", 
        "BlockIOWeight": "18446744073709551615", 
        "CPUAccounting": "no", 
        "CPUQuotaPerSecUSec": "infinity", 
        "CPUSchedulingPolicy": "0", 
        "CPUSchedulingPriority": "0", 
        "CPUSchedulingResetOnFork": "no", 
        "CPUShares": "18446744073709551615", 
        "CanIsolate": "no", 
        "CanReload": "yes", 
        "CanStart": "yes", 
        "CanStop": "yes", 
        "CapabilityBoundingSet": "18446744073709551615", 
        "ConditionResult": "yes", 
        "ConditionTimestamp": "Thu 2018-09-06 01:51:01 CST", 
        "ConditionTimestampMonotonic": "26428509553", 
        "Conflicts": "shutdown.target", 
        "ControlGroup": "/system.slice/httpd.service", 
        "ControlPID": "0", 
        "DefaultDependencies": "yes", 
        "Delegate": "no", 
        "Description": "The Apache HTTP Server", 
        "DevicePolicy": "auto", 
        "Documentation": "man:httpd(8) man:apachectl(8)", 
        "EnvironmentFile": "/etc/sysconfig/httpd (ignore_errors=no)", 
        "ExecMainCode": "0", 
        "ExecMainExitTimestampMonotonic": "0", 
        "ExecMainPID": "21723", 
        "ExecMainStartTimestamp": "Thu 2018-09-06 01:51:01 CST", 
        "ExecMainStartTimestampMonotonic": "26428512147", 
        "ExecMainStatus": "0", 
        "ExecReload": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -k graceful ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "ExecStart": "{ path=/usr/sbin/httpd ; argv[]=/usr/sbin/httpd $OPTIONS -DFOREGROUND ; ignore_errors=no ; start_time=[Thu 2018-09-06 01:51:01 CST] ; stop_time=[n/a] ; pid=21723 ; code=(null) ; status=0/0 }", 
        "ExecStop": "{ path=/bin/kill ; argv[]=/bin/kill -WINCH ${MAINPID} ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", 
        "FailureAction": "none", 
        "FileDescriptorStoreMax": "0", 
        "FragmentPath": "/usr/lib/systemd/system/httpd.service", 
        "GuessMainPID": "yes", 
        "IOScheduling": "0", 
        "Id": "httpd.service", 
        "IgnoreOnIsolate": "no", 
        "IgnoreOnSnapshot": "no", 
        "IgnoreSIGPIPE": "yes", 
        "InactiveEnterTimestampMonotonic": "0", 
        "InactiveExitTimestamp": "Thu 2018-09-06 01:51:01 CST", 
        "InactiveExitTimestampMonotonic": "26428512182", 
        "JobTimeoutAction": "none", 
        "JobTimeoutUSec": "0", 
        "KillMode": "control-group", 
        "KillSignal": "18", 
        "LimitAS": "18446744073709551615", 
        "LimitCORE": "18446744073709551615", 
        "LimitCPU": "18446744073709551615", 
        "LimitDATA": "18446744073709551615", 
        "LimitFSIZE": "18446744073709551615", 
        "LimitLOCKS": "18446744073709551615", 
        "LimitMEMLOCK": "65536", 
        "LimitMSGQUEUE": "819200", 
        "LimitNICE": "0", 
        "LimitNOFILE": "4096", 
        "LimitNPROC": "15013", 
        "LimitRSS": "18446744073709551615", 
        "LimitRTPRIO": "0", 
        "LimitRTTIME": "18446744073709551615", 
        "LimitSIGPENDING": "15013", 
        "LimitSTACK": "18446744073709551615", 
        "LoadState": "loaded", 
        "MainPID": "21723", 
        "MemoryAccounting": "no", 
        "MemoryCurrent": "18446744073709551615", 
        "MemoryLimit": "18446744073709551615", 
        "MountFlags": "0", 
        "Names": "httpd.service", 
        "NeedDaemonReload": "no", 
        "Nice": "0", 
        "NoNewPrivileges": "no", 
        "NonBlocking": "no", 
        "NotifyAccess": "main", 
        "OOMScoreAdjust": "0", 
        "OnFailureJobMode": "replace", 
        "PermissionsStartOnly": "no", 
        "PrivateDevices": "no", 
        "PrivateNetwork": "no", 
        "PrivateTmp": "yes", 
        "ProtectHome": "no", 
        "ProtectSystem": "no", 
        "RefuseManualStart": "no", 
        "RefuseManualStop": "no", 
        "RemainAfterExit": "no", 
        "Requires": "-.mount basic.target", 
        "RequiresMountsFor": "/var/tmp", 
        "Restart": "no", 
        "RestartUSec": "100ms", 
        "Result": "success", 
        "RootDirectoryStartOnly": "no", 
        "RuntimeDirectoryMode": "0755", 
        "SameProcessGroup": "no", 
        "SecureBits": "0", 
        "SendSIGHUP": "no", 
        "SendSIGKILL": "yes", 
        "Slice": "system.slice", 
        "StandardError": "inherit", 
        "StandardInput": "null", 
        "StandardOutput": "journal", 
        "StartLimitAction": "none", 
        "StartLimitBurst": "5", 
        "StartLimitInterval": "10000000", 
        "StartupBlockIOWeight": "18446744073709551615", 
        "StartupCPUShares": "18446744073709551615", 
        "StatusErrno": "0", 
        "StatusText": "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec", 
        "StopWhenUnneeded": "no", 
        "SubState": "running", 
        "SyslogLevelPrefix": "yes", 
        "SyslogPriority": "30", 
        "SystemCallErrorNumber": "0", 
        "TTYReset": "no", 
        "TTYVHangup": "no", 
        "TTYVTDisallocate": "no", 
        "TimeoutStartUSec": "1min 30s", 
        "TimeoutStopUSec": "1min 30s", 
        "TimerSlackNSec": "50000", 
        "Transient": "no", 
        "Type": "notify", 
        "UMask": "0022", 
        "UnitFilePreset": "disabled", 
        "UnitFileState": "enabled", 
        "WantedBy": "multi-user.target", 
        "Wants": "system.slice", 
        "WatchdogTimestamp": "Thu 2018-09-06 01:51:01 CST", 
        "WatchdogTimestampMonotonic": "26428645975", 
        "WatchdogUSec": "0"
    }
}
shell 模块【管理主机可以通过ansible的shell模块在被控制主机上执行命令】
  • help
[root@master ~]# ansible-doc -s shell
- name: Execute commands in nodes.
  shell:
      chdir:                 # cd into this directory before running the command
      creates:               # a filename, when it already exists, this step will *not* be run.
      executable:            # change the shell used to execute the command. Should be an absolute path to the executable.
      free_form:             # (required) The shell module takes a free form command to run, as a string.  There's not an actual option named "free form".  See the examples!
      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.
      warn:                  # if command warnings are on in ansible.cfg, do not warn about this particular line if set to no/false.
  • 通过shell对用户进行密码设置
[root@master ~]# ansible slave1 -m shell -a 'echo 123456 | passwd --stdin slave1'
192.168.27.111 | SUCCESS | rc=0 >>
Changing password for user slave1.
passwd: all authentication tokens updated successfully.
script 模块【将本地脚本复制到被管理主机上进行运行】【使用“相对”路径】
  • help
[root@master ~]# ansible-doc -s script
- name: Runs a local script on a remote node after transferring it
  script:
      chdir:                 # cd into this directory on the remote node before running the script
      creates:               # a filename, when it already exists, this step will *not* be run.
      decrypt:               # This option controls the autodecryption of source files using vault.
      executable:            # Name or path of a executable to invoke the script with
      free_form:             # (required) Path to the local script file followed by optional arguments. There is no parameter actually named 'free form'; see the examples!
      removes:               # a filename, when it does not exist, this step will *not* be run.
  • 控制主机编写脚本
[root@master ~]# vim test_script.sh

#!/bin/bash
echo "This is test for ansible script ~ " > /root/testansiscript.txt
  • 控制主机进行下发
[root@master ~]# chmod +x test_script.sh

[root@master ~]# ansible slave1 -m script -a 'test_script.sh'
192.168.27.111 | SUCCESS => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to 192.168.27.111 closed.\r\n", 
    "stderr_lines": [
        "Shared connection to 192.168.27.111 closed."
    ], 
    "stdout": "", 
    "stdout_lines": []
}
  • 查看执行结果
[root@master ~]# ansible slave1 -m command -a 'cat /root/testansiscript.txt'
192.168.27.111 | SUCCESS | rc=0 >>
This is test for ansible script ~  // 输出结果查看
setup 模块【用于模块收集,查看被管理主机的facts】
  • help
[root@master ~]# ansible-doc -s setup
- name: Gathers facts about remote hosts
  setup:
      fact_path:             # path used for local ansible facts (*.fact) - files in this dir will be run (if executable) and their results be added to ansible_local facts if a file is not
                               executable it is read. Check notes for Windows options. (from 2.1 on) File/results format can be json or ini-format
      filter:                # if supplied, only return facts that match this shell-style (fnmatch) wildcard.
      gather_subset:         # if supplied, restrict the additional facts collected to the given subset. Possible values: all, min, hardware, network, virtual, ohai, and facter Can specify
                               a list of values to specify a larger subset. Values can also be used with an initial `!' to specify that that specific subset
                               should not be collected.  For instance: !hardware, !network, !virtual, !ohai, !facter. If !all is specified then only the min
                               subset is collected. To avoid collecting even the min subset, specify !all and !min subsets. To collect only specific facts,
                               use !all, !min, and specify the particular fact subsets. Use the filter parameter if you do not want to display some collected
                               facts.
      gather_timeout:        # Set the default timeout in seconds for individual fact gathering
  • 收集被控制主机信息
[root@master ~]# ansible slave1 -m setup
192.168.27.111 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.27.111"
        ], 
        "ansible_all_ipv6_addresses": [
            "fe80::631d:36fd:a7f:944e"
        ], 
        "ansible_apparmor": {
            "status": "disabled"
        }, 
        "ansible_architecture": "x86_64", 
        "ansible_bios_date": "07/02/2015", 
        "ansible_bios_version": "6.00", 
        "ansible_cmdline": {
            "BOOT_IMAGE": "/vmlinuz-3.10.0-514.el7.x86_64", 
            "LANG": "en_US.UTF-8", 
            "crashkernel": "auto", 
            "quiet": true, 
            "rd.lvm.lv": "cl/swap", 
            "rhgb": true, 
            "ro": true, 
            "root": "/dev/mapper/cl-root"
        }, 
        "ansible_date_time": {
            "date": "2018-09-06", 
            "day": "06", 
            "epoch": "1536229359", 
            "hour": "18", 
            "iso8601": "2018-09-06T10:22:39Z", 
            "iso8601_basic": "20180906T182239463350", 
            "iso8601_basic_short": "20180906T182239", 
            "iso8601_micro": "2018-09-06T10:22:39.463629Z", 
            "minute": "22", 
            "month": "09", 
            "second": "39", 
            "time": "18:22:39", 
            "tz": "CST", 
            "tz_offset": "+0800", 
            "weekday": "Thursday", 
            "weekday_number": "4", 
            "weeknumber": "36", 
            "year": "2018"
        }, 
        "ansible_default_ipv4": {
            "address": "192.168.27.111", 
            "alias": "ens33", 
            "broadcast": "192.168.27.255", 
            "gateway": "192.168.27.2", 
            "interface": "ens33", 
            "macaddress": "00:0c:29:81:67:88", 
            "mtu": 1500, 
            "netmask": "255.255.255.0", 
            "network": "192.168.27.0", 
            "type": "ether"
        }, 
        "ansible_default_ipv6": {}, 
        "ansible_device_links": {
            "ids": {
                "dm-0": [
                    "dm-name-cl-root", 
                    "dm-uuid-LVM-eWfX15fr1Au5dIaeMWKvYuk8kT75xYhX5iXPveQK5jRVXaLjlclxtdNsf75DRpMW"
                ], 
                "dm-1": [
                    "dm-name-cl-swap", 
                    "dm-uuid-LVM-eWfX15fr1Au5dIaeMWKvYuk8kT75xYhXFTYT2OIzoFKuELpHpfsf4PpUpu68AWU0"
                ], 
                "sda3": [
                    "lvm-pv-uuid-hDrPJx-cSPI-REbt-I8fa-JQ1z-lucd-TLJ0PL"
                ], 
                "sr0": [
                    "ata-VMware_Virtual_IDE_CDROM_Drive_10000000000000000001"
                ]
            }, 
            "labels": {
                "sr0": [
                    "CentOS\\x207\\x20x86_64"
                ]
            }, 
            "masters": {
                "sda3": [
                    "dm-0", 
                    "dm-1"
                ]
            }, 
            "uuids": {
                "dm-0": [
                    "bb1a1f95-08c1-46e9-aec6-560f4e4921b3"
                ], 
                "dm-1": [
                    "2bc32199-9524-4711-8a47-ae2292ce2c20"
                ], 
                "sda2": [
                    "cdb71907-32f0-41b9-aa55-9746d13a8532"
                ], 
                "sr0": [
                    "2016-12-05-13-55-45-00"
                ]
            }
        }, 
        "ansible_devices": {
            "dm-0": {
                "holders": [], 
                "host": "", 
                "links": {
                    "ids": [
                        "dm-name-cl-root", 
                        "dm-uuid-LVM-eWfX15fr1Au5dIaeMWKvYuk8kT75xYhX5iXPveQK5jRVXaLjlclxtdNsf75DRpMW"
                    ], 
                    "labels": [], 
                    "masters": [], 
                    "uuids": [
                        "bb1a1f95-08c1-46e9-aec6-560f4e4921b3"
                    ]
                }, 
                "model": null, 
                "partitions": {}, 
                "removable": "0", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "", 
                "sectors": "24748032", 
                "sectorsize": "512", 
                "size": "11.80 GB", 
                "support_discard": "0", 
                "vendor": null, 
                "virtual": 1
            }, 
            "dm-1": {
                "holders": [], 
                "host": "", 
                "links": {
                    "ids": [
                        "dm-name-cl-swap", 
                        "dm-uuid-LVM-eWfX15fr1Au5dIaeMWKvYuk8kT75xYhXFTYT2OIzoFKuELpHpfsf4PpUpu68AWU0"
                    ], 
                    "labels": [], 
                    "masters": [], 
                    "uuids": [
                        "2bc32199-9524-4711-8a47-ae2292ce2c20"
                    ]
                }, 
                "model": null, 
                "partitions": {}, 
                "removable": "0", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "", 
                "sectors": "16777216", 
                "sectorsize": "512", 
                "size": "8.00 GB", 
                "support_discard": "0", 
                "vendor": null, 
                "virtual": 1
            }, 
            "sda": {
                "holders": [], 
                "host": "SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)", 
                "links": {
                    "ids": [], 
                    "labels": [], 
                    "masters": [], 
                    "uuids": []
                }, 
                "model": "VMware Virtual S", 
                "partitions": {
                    "sda1": {
                        "holders": [], 
                        "links": {
                            "ids": [], 
                            "labels": [], 
                            "masters": [], 
                            "uuids": []
                        }, 
                        "sectors": "4096", 
                        "sectorsize": 512, 
                        "size": "2.00 MB", 
                        "start": "2048", 
                        "uuid": null
                    }, 
                    "sda2": {
                        "holders": [], 
                        "links": {
                            "ids": [], 
                            "labels": [], 
                            "masters": [], 
                            "uuids": [
                                "cdb71907-32f0-41b9-aa55-9746d13a8532"
                            ]
                        }, 
                        "sectors": "409600", 
                        "sectorsize": 512, 
                        "size": "200.00 MB", 
                        "start": "6144", 
                        "uuid": "cdb71907-32f0-41b9-aa55-9746d13a8532"
                    }, 
                    "sda3": {
                        "holders": [
                            "cl-root", 
                            "cl-swap"
                        ], 
                        "links": {
                            "ids": [
                                "lvm-pv-uuid-hDrPJx-cSPI-REbt-I8fa-JQ1z-lucd-TLJ0PL"
                            ], 
                            "labels": [], 
                            "masters": [
                                "dm-0", 
                                "dm-1"
                            ], 
                            "uuids": []
                        }, 
                        "sectors": "41527296", 
                        "sectorsize": 512, 
                        "size": "19.80 GB", 
                        "start": "415744", 
                        "uuid": null
                    }
                }, 
                "removable": "0", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "deadline", 
                "sectors": "41943040", 
                "sectorsize": "512", 
                "size": "20.00 GB", 
                "support_discard": "0", 
                "vendor": "VMware,", 
                "virtual": 1
            }, 
            "sr0": {
                "holders": [], 
                "host": "IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)", 
                "links": {
                    "ids": [
                        "ata-VMware_Virtual_IDE_CDROM_Drive_10000000000000000001"
                    ], 
                    "labels": [
                        "CentOS\\x207\\x20x86_64"
                    ], 
                    "masters": [], 
                    "uuids": [
                        "2016-12-05-13-55-45-00"
                    ]
                }, 
                "model": "VMware IDE CDR10", 
                "partitions": {}, 
                "removable": "1", 
                "rotational": "1", 
                "sas_address": null, 
                "sas_device_handle": null, 
                "scheduler_mode": "cfq", 
                "sectors": "8554496", 
                "sectorsize": "2048", 
                "size": "4.08 GB", 
                "support_discard": "0", 
                "vendor": "NECVMWar", 
                "virtual": 1
            }
        }, 
        "ansible_distribution": "CentOS", 
        "ansible_distribution_file_parsed": true, 
        "ansible_distribution_file_path": "/etc/redhat-release", 
        "ansible_distribution_file_variety": "RedHat", 
        "ansible_distribution_major_version": "7", 
        "ansible_distribution_release": "Core", 
        "ansible_distribution_version": "7.3.1611", 
        "ansible_dns": {
            "nameservers": [
                "114.114.114.114"
            ]
        }, 
        "ansible_domain": "", 
        "ansible_effective_group_id": 0, 
        "ansible_effective_user_id": 0, 
        "ansible_ens33": {
            "active": true, 
            "device": "ens33", 
            "features": {
                "busy_poll": "off [fixed]", 
                "fcoe_mtu": "off [fixed]", 
                "generic_receive_offload": "on", 
                "generic_segmentation_offload": "on", 
                "highdma": "off [fixed]", 
                "hw_tc_offload": "off [fixed]", 
                "l2_fwd_offload": "off [fixed]", 
                "large_receive_offload": "off [fixed]", 
                "loopback": "off [fixed]", 
                "netns_local": "off [fixed]", 
                "ntuple_filters": "off [fixed]", 
                "receive_hashing": "off [fixed]", 
                "rx_all": "off", 
                "rx_checksumming": "off", 
                "rx_fcs": "off", 
                "rx_vlan_filter": "on [fixed]", 
                "rx_vlan_offload": "on", 
                "rx_vlan_stag_filter": "off [fixed]", 
                "rx_vlan_stag_hw_parse": "off [fixed]", 
                "scatter_gather": "on", 
                "tcp_segmentation_offload": "on", 
                "tx_checksum_fcoe_crc": "off [fixed]", 
                "tx_checksum_ip_generic": "on", 
                "tx_checksum_ipv4": "off [fixed]", 
                "tx_checksum_ipv6": "off [fixed]", 
                "tx_checksum_sctp": "off [fixed]", 
                "tx_checksumming": "on", 
                "tx_fcoe_segmentation": "off [fixed]", 
                "tx_gre_segmentation": "off [fixed]", 
                "tx_gso_robust": "off [fixed]", 
                "tx_ipip_segmentation": "off [fixed]", 
                "tx_lockless": "off [fixed]", 
                "tx_mpls_segmentation": "off [fixed]", 
                "tx_nocache_copy": "off", 
                "tx_scatter_gather": "on", 
                "tx_scatter_gather_fraglist": "off [fixed]", 
                "tx_sctp_segmentation": "off [fixed]", 
                "tx_sit_segmentation": "off [fixed]", 
                "tx_tcp6_segmentation": "off [fixed]", 
                "tx_tcp_ecn_segmentation": "off [fixed]", 
                "tx_tcp_segmentation": "on", 
                "tx_udp_tnl_segmentation": "off [fixed]", 
                "tx_vlan_offload": "on [fixed]", 
                "tx_vlan_stag_hw_insert": "off [fixed]", 
                "udp_fragmentation_offload": "off [fixed]", 
                "vlan_challenged": "off [fixed]"
            }, 
            "hw_timestamp_filters": [], 
            "ipv4": {
                "address": "192.168.27.111", 
                "broadcast": "192.168.27.255", 
                "netmask": "255.255.255.0", 
                "network": "192.168.27.0"
            }, 
            "ipv6": [
                {
                    "address": "fe80::631d:36fd:a7f:944e", 
                    "prefix": "64", 
                    "scope": "link"
                }
            ], 
            "macaddress": "00:0c:29:81:67:88", 
            "module": "e1000", 
            "mtu": 1500, 
            "pciid": "0000:02:01.0", 
            "promisc": false, 
            "speed": 1000, 
            "timestamping": [
                "tx_software", 
                "rx_software", 
                "software"
            ], 
            "type": "ether"
        }, 
        "ansible_env": {
            "HOME": "/root", 
            "LANG": "en_US.UTF-8", 
            "LESSOPEN": "||/usr/bin/lesspipe.sh %s", 
            "LOGNAME": "root", 
            "LS_COLORS": "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:", 
            "MAIL": "/var/mail/root", 
            "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin", 
            "PWD": "/root", 
            "SELINUX_LEVEL_REQUESTED": "", 
            "SELINUX_ROLE_REQUESTED": "", 
            "SELINUX_USE_CURRENT_RANGE": "", 
            "SHELL": "/bin/bash", 
            "SHLVL": "2", 
            "SSH_CLIENT": "192.168.27.110 44534 22", 
            "SSH_CONNECTION": "192.168.27.110 44534 192.168.27.111 22", 
            "SSH_TTY": "/dev/pts/1", 
            "TERM": "xterm", 
            "USER": "root", 
            "XDG_RUNTIME_DIR": "/run/user/0", 
            "XDG_SESSION_ID": "7", 
            "_": "/usr/bin/python"
        }, 
        "ansible_fips": false, 
        "ansible_form_factor": "Other", 
        "ansible_fqdn": "slave1", 
        "ansible_hostname": "slave1", 
        "ansible_interfaces": [
            "lo", 
            "ens33"
        ], 
        "ansible_is_chroot": false, 
        "ansible_iscsi_iqn": "", 
        "ansible_kernel": "3.10.0-514.el7.x86_64", 
        "ansible_lo": {
            "active": true, 
            "device": "lo", 
            "features": {
                "busy_poll": "off [fixed]", 
                "fcoe_mtu": "off [fixed]", 
                "generic_receive_offload": "on", 
                "generic_segmentation_offload": "on", 
                "highdma": "on [fixed]", 
                "hw_tc_offload": "off [fixed]", 
                "l2_fwd_offload": "off [fixed]", 
                "large_receive_offload": "off [fixed]", 
                "loopback": "on [fixed]", 
                "netns_local": "on [fixed]", 
                "ntuple_filters": "off [fixed]", 
                "receive_hashing": "off [fixed]", 
                "rx_all": "off [fixed]", 
                "rx_checksumming": "on [fixed]", 
                "rx_fcs": "off [fixed]", 
                "rx_vlan_filter": "off [fixed]", 
                "rx_vlan_offload": "off [fixed]", 
                "rx_vlan_stag_filter": "off [fixed]", 
                "rx_vlan_stag_hw_parse": "off [fixed]", 
                "scatter_gather": "on", 
                "tcp_segmentation_offload": "on", 
                "tx_checksum_fcoe_crc": "off [fixed]", 
                "tx_checksum_ip_generic": "on [fixed]", 
                "tx_checksum_ipv4": "off [fixed]", 
                "tx_checksum_ipv6": "off [fixed]", 
                "tx_checksum_sctp": "on [fixed]", 
                "tx_checksumming": "on", 
                "tx_fcoe_segmentation": "off [fixed]", 
                "tx_gre_segmentation": "off [fixed]", 
                "tx_gso_robust": "off [fixed]", 
                "tx_ipip_segmentation": "off [fixed]", 
                "tx_lockless": "on [fixed]", 
                "tx_mpls_segmentation": "off [fixed]", 
                "tx_nocache_copy": "off [fixed]", 
                "tx_scatter_gather": "on [fixed]", 
                "tx_scatter_gather_fraglist": "on [fixed]", 
                "tx_sctp_segmentation": "on", 
                "tx_sit_segmentation": "off [fixed]", 
                "tx_tcp6_segmentation": "on", 
                "tx_tcp_ecn_segmentation": "on", 
                "tx_tcp_segmentation": "on", 
                "tx_udp_tnl_segmentation": "off [fixed]", 
                "tx_vlan_offload": "off [fixed]", 
                "tx_vlan_stag_hw_insert": "off [fixed]", 
                "udp_fragmentation_offload": "on", 
                "vlan_challenged": "on [fixed]"
            }, 
            "hw_timestamp_filters": [], 
            "ipv4": {
                "address": "127.0.0.1", 
                "broadcast": "host", 
                "netmask": "255.0.0.0", 
                "network": "127.0.0.0"
            }, 
            "ipv6": [
                {
                    "address": "::1", 
                    "prefix": "128", 
                    "scope": "host"
                }
            ], 
            "mtu": 65536, 
            "promisc": false, 
            "timestamping": [
                "rx_software", 
                "software"
            ], 
            "type": "loopback"
        }, 
        "ansible_local": {}, 
        "ansible_lsb": {}, 
        "ansible_lvm": {
            "lvs": {
                "root": {
                    "size_g": "11.80", 
                    "vg": "cl"
                }, 
                "swap": {
                    "size_g": "8.00", 
                    "vg": "cl"
                }
            }, 
            "pvs": {
                "/dev/sda3": {
                    "free_g": "0", 
                    "size_g": "19.80", 
                    "vg": "cl"
                }
            }, 
            "vgs": {
                "cl": {
                    "free_g": "0", 
                    "num_lvs": "2", 
                    "num_pvs": "1", 
                    "size_g": "19.80"
                }
            }
        }, 
        "ansible_machine": "x86_64", 
        "ansible_machine_id": "7acb62a90dbf40ab90991ce7ead2fff6", 
        "ansible_memfree_mb": 3476, 
        "ansible_memory_mb": {
            "nocache": {
                "free": 3585, 
                "used": 189
            }, 
            "real": {
                "free": 3476, 
                "total": 3774, 
                "used": 298
            }, 
            "swap": {
                "cached": 0, 
                "free": 8191, 
                "total": 8191, 
                "used": 0
            }
        }, 
        "ansible_memtotal_mb": 3774, 
        "ansible_mounts": [
            {
                "block_available": 2713548, 
                "block_size": 4096, 
                "block_total": 3090944, 
                "block_used": 377396, 
                "device": "/dev/mapper/cl-root", 
                "fstype": "xfs", 
                "inode_available": 6130740, 
                "inode_total": 6187008, 
                "inode_used": 56268, 
                "mount": "/", 
                "options": "rw,seclabel,relatime,attr2,inode64,noquota", 
                "size_available": 11114692608, 
                "size_total": 12660506624, 
                "uuid": "bb1a1f95-08c1-46e9-aec6-560f4e4921b3"
            }, 
            {
                "block_available": 20561, 
                "block_size": 4096, 
                "block_total": 50345, 
                "block_used": 29784, 
                "device": "/dev/sda2", 
                "fstype": "xfs", 
                "inode_available": 102070, 
                "inode_total": 102400, 
                "inode_used": 330, 
                "mount": "/boot", 
                "options": "rw,seclabel,relatime,attr2,inode64,noquota", 
                "size_available": 84217856, 
                "size_total": 206213120, 
                "uuid": "cdb71907-32f0-41b9-aa55-9746d13a8532"
            }
        ], 
        "ansible_nodename": "slave1", 
        "ansible_os_family": "RedHat", 
        "ansible_pkg_mgr": "yum", 
        "ansible_processor": [
            "0", 
            "GenuineIntel", 
            "Intel(R) Core(TM) i5-4210M CPU @ 2.60GHz", 
            "1", 
            "GenuineIntel", 
            "Intel(R) Core(TM) i5-4210M CPU @ 2.60GHz"
        ], 
        "ansible_processor_cores": 2, 
        "ansible_processor_count": 1, 
        "ansible_processor_threads_per_core": 1, 
        "ansible_processor_vcpus": 2, 
        "ansible_product_name": "VMware Virtual Platform", 
        "ansible_product_serial": "VMware-56 4d d4 e4 22 70 28 1c-4d 4d ae 4d b2 81 67 88", 
        "ansible_product_uuid": "E4D44D56-7022-1C28-4D4D-AE4DB2816788", 
        "ansible_product_version": "None", 
        "ansible_python": {
            "executable": "/usr/bin/python", 
            "has_sslcontext": true, 
            "type": "CPython", 
            "version": {
                "major": 2, 
                "micro": 5, 
                "minor": 7, 
                "releaselevel": "final", 
                "serial": 0
            }, 
            "version_info": [
                2, 
                7, 
                5, 
                "final", 
                0
            ]
        }, 
        "ansible_python_version": "2.7.5", 
        "ansible_real_group_id": 0, 
        "ansible_real_user_id": 0, 
        "ansible_selinux": {
            "config_mode": "enforcing", 
            "mode": "enforcing", 
            "policyvers": 28, 
            "status": "enabled", 
            "type": "targeted"
        }, 
        "ansible_selinux_python_present": true, 
        "ansible_service_mgr": "systemd", 
        "ansible_ssh_host_key_ecdsa_public": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJ2c5yBJb7fHxSpnu7tB4fAVHA/S4nxZm4IT7YlQxWl0wn1mJIdJq+IKWS89h5K/RibHQzbHYXW0BRfnZqaEW5M=", 
        "ansible_ssh_host_key_ed25519_public": "AAAAC3NzaC1lZDI1NTE5AAAAIGloC57+7CHx9Hr7PzGHFVZnIkcp+hkwGTNT7OkQ2bLZ", 
        "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAADAQABAAABAQCiLHxUUuJYdfcVyH+S4amrXgBqmzKwYgQMkaC5i1QzFw/lbLDF6jXOFkrovN9XATtctIkI1FZAd+XOwI5TT0fi3tTzX8F04Pma0SBI66a51uJt5FJ4MFzwWCYB3lhAp8rry1kYIvflmB72D82/yVGICPVFtV0fUi9a1IuKJl7bRoRbrr5CLjwX0EaEijxa1ADuTb0gL2MMa/Jt6kaCCtG8xNCe6KSsNEUfa9ElmSdz9e9Bu5Fs8V1ptb7jR4pGFQxjJ+3ymWjtex0bDRFIcBJFio00Gcozy+Bm0/6jyVu9g4MPkEtyebi9GhtmzcjObEhR5ULSL0fORm03i05YzUNf", 
        "ansible_swapfree_mb": 8191, 
        "ansible_swaptotal_mb": 8191, 
        "ansible_system": "Linux", 
        "ansible_system_capabilities": [
            "cap_chown", 
            "cap_dac_override", 
            "cap_dac_read_search", 
            "cap_fowner", 
            "cap_fsetid", 
            "cap_kill", 
            "cap_setgid", 
            "cap_setuid", 
            "cap_setpcap", 
            "cap_linux_immutable", 
            "cap_net_bind_service", 
            "cap_net_broadcast", 
            "cap_net_admin", 
            "cap_net_raw", 
            "cap_ipc_lock", 
            "cap_ipc_owner", 
            "cap_sys_module", 
            "cap_sys_rawio", 
            "cap_sys_chroot", 
            "cap_sys_ptrace", 
            "cap_sys_pacct", 
            "cap_sys_admin", 
            "cap_sys_boot", 
            "cap_sys_nice", 
            "cap_sys_resource", 
            "cap_sys_time", 
            "cap_sys_tty_config", 
            "cap_mknod", 
            "cap_lease", 
            "cap_audit_write", 
            "cap_audit_control", 
            "cap_setfcap", 
            "cap_mac_override", 
            "cap_mac_admin", 
            "cap_syslog", 
            "35", 
            "36+ep"
        ], 
        "ansible_system_capabilities_enforced": "True", 
        "ansible_system_vendor": "VMware, Inc.", 
        "ansible_uptime_seconds": 1964, 
        "ansible_user_dir": "/root", 
        "ansible_user_gecos": "root", 
        "ansible_user_gid": 0, 
        "ansible_user_id": "root", 
        "ansible_user_shell": "/bin/bash", 
        "ansible_user_uid": 0, 
        "ansible_userspace_architecture": "x86_64", 
        "ansible_userspace_bits": "64", 
        "ansible_virtualization_role": "guest", 
        "ansible_virtualization_type": "VMware", 
        "gather_subset": [
            "all"
        ], 
        "module_setup": true
    }, 
    "changed": false
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值