ansible模块yum、services、setup

ansible模块 yum:

[[email protected] ~]# ansible-doc -s yum
less 436
Copyright (C) 1984-2009 Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less
- name: M a n a g e s   p a c k a g e s   w i t h   t h e   I ( y u m )   p a c k a g e   m a n a g e r
  action: yum
      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‘.
      disablerepo            # `Repoid‘ of repositories to disable for the install/update operation. These repos will not persist beyond the transaction. When specifyi
      enablerepo             # `Repoid‘ of repositories to enable for the install/update operation. These repos will not persist beyond the transaction. When specifyin
      list                   # Various (non-idempotent) commands for usage with `/usr/bin/ansible‘ and `not‘ playbooks. See examples.
      name=                  # Package name, or package specifier with version, like `name-1.0‘. When using state=latest, this can be ‘*‘ which means run: yum -y updat
      state                  # Whether to install (`present‘, `latest‘), or remove (`absent‘) a package.
      update_cache           # Force updating the cache. Has an effect only if state is `present‘ or `latest‘.
[[email protected] ~]#

安装httpd服务

[[email protected] ~]# ansible testservers -m yum -a ‘name=httpd state=present‘
192.168.100.132 | success >> {
    "changed": true, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror, refresh-packagekit, security\nLoading mirror speeds from cached hostfile\n * base: mirrors.btte.net\n * epel: mirrors.hustunique.com\n * extras: mirrors.btte.net\n * updates: mirrors.yun-idc.com\nSetting up Install Process\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.15-47.el6.centos.3 will be installed\n--> Processing Dependency: httpd-tools = 2.2.15-47.el6.centos.3 for package: httpd-2.2.15-47.el6.centos.3.x86_64\n--> Running transaction check\n---> Package httpd-tools.x86_64 0:2.2.15-29.el6.centos will be updated\n---> Package httpd-tools.x86_64 0:2.2.15-47.el6.centos.3 will be an update\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package          Arch        Version                        Repository    Size\n================================================================================\nInstalling:\n httpd            x86_64      2.2.15-47.el6.centos.3         updates      831 k\nUpdating for dependencies:\n httpd-tools      x86_64      2.2.15-47.el6.centos.3         updates       77 k\n\nTransaction Summary\n================================================================================\nInstall       1 Package(s)\nUpgrade       1 Package(s)\n\nTotal download size: 908 k\nDownloading Packages:\n--------------------------------------------------------------------------------\nTotal                                           4.4 MB/s | 908 kB     00:00     \nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r  Updating   : httpd-tools-2.2.15-47.el6.centos.3.x86_64                    1/3 \n\r  Installing : httpd-2.2.15-47.el6.centos.3.x86_64                          2/3 \n\r  Cleanup    : httpd-tools-2.2.15-29.el6.centos.x86_64                      3/3 \n\r  Verifying  : httpd-tools-2.2.15-47.el6.centos.3.x86_64                    1/3 \n\r  Verifying  : httpd-2.2.15-47.el6.centos.3.x86_64                          2/3 \n\r  Verifying  : httpd-tools-2.2.15-29.el6.centos.x86_64                      3/3 \n\nInstalled:\n  httpd.x86_64 0:2.2.15-47.el6.centos.3                                         \n\nDependency Updated:\n  httpd-tools.x86_64 0:2.2.15-47.el6.centos.3                                   \n\nComplete!\n"
    ]
}

192.168.100.131 | success >> {
    "changed": true, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * epel: mirrors.opencas.cn\nSetting up Install Process\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.15-29.el6.centos will be installed\n--> Processing Dependency: httpd-tools = 2.2.15-29.el6.centos for package: httpd-2.2.15-29.el6.centos.x86_64\n--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-29.el6.centos.x86_64\n--> Processing Dependency: /etc/mime.types for package: httpd-2.2.15-29.el6.centos.x86_64\n--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.2.15-29.el6.centos.x86_64\n--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.2.15-29.el6.centos.x86_64\n--> Running transaction check\n---> Package apr.x86_64 0:1.3.9-5.el6_2 will be installed\n---> Package apr-util.x86_64 0:1.3.9-3.el6_0.1 will be installed\n---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed\n---> Package httpd-tools.x86_64 0:2.2.15-29.el6.centos will be installed\n---> Package mailcap.noarch 0:2.1.31-2.el6 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package              Arch          Version                      Repository\n                                                                           Size\n================================================================================\nInstalling:\n httpd                x86_64        2.2.15-29.el6.centos         1        821 k\nInstalling for dependencies:\n apr                  x86_64        1.3.9-5.el6_2                1        123 k\n apr-util             x86_64        1.3.9-3.el6_0.1              1         87 k\n apr-util-ldap        x86_64        1.3.9-3.el6_0.1              1         15 k\n httpd-tools          x86_64        2.2.15-29.el6.centos         1         73 k\n mailcap              noarch        2.1.31-2.el6                 1         27 k\n\nTransaction Summary\n================================================================================\nInstall       6 Package(s)\n\nTotal download size: 1.1 M\nInstalled size: 3.6 M\nDownloading Packages:\n--------------------------------------------------------------------------------\nTotal                                            13 MB/s | 1.1 MB     00:00     \nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r  Installing : apr-1.3.9-5.el6_2.x86_64                                     1/6 \n\r  Installing : apr-util-1.3.9-3.el6_0.1.x86_64                              2/6 \n\r  Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                         3/6 \n\r  Installing : httpd-tools-2.2.15-29.el6.centos.x86_64                      4/6 \n\r  Installing : mailcap-2.1.31-2.el6.noarch                                  5/6 \n\r  Installing : httpd-2.2.15-29.el6.centos.x86_64                            6/6 \n\r  Verifying  : httpd-2.2.15-29.el6.centos.x86_64                            1/6 \n\r  Verifying  : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                         2/6 \n\r  Verifying  : httpd-tools-2.2.15-29.el6.centos.x86_64                      3/6 \n\r  Verifying  : apr-1.3.9-5.el6_2.x86_64                                     4/6 \n\r  Verifying  : mailcap-2.1.31-2.el6.noarch                                  5/6 \n\r  Verifying  : apr-util-1.3.9-3.el6_0.1.x86_64                              6/6 \n\nInstalled:\n  httpd.x86_64 0:2.2.15-29.el6.centos                                           \n\nDependency Installed:\n  apr.x86_64 0:1.3.9-5.el6_2                                                    \n  apr-util.x86_64 0:1.3.9-3.el6_0.1                                             \n  apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1                                        \n  httpd-tools.x86_64 0:2.2.15-29.el6.centos                                     \n  mailcap.noarch 0:2.1.31-2.el6                                                 \n\nComplete!\n"
    ]
}

name:可以指定版本号,否定为默认最新

卸载 httpd 服务:

[[email protected] ~]# ansible testservers -m yum -a ‘name=httpd state=absent ‘
192.168.100.131 | success >> {
    "changed": true, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror\nSetting up Remove Process\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.15-29.el6.centos 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.2.15-29.el6.centos          @1          2.9 M\n\nTransaction Summary\n================================================================================\nRemove        1 Package(s)\n\nInstalled size: 2.9 M\nDownloading Packages:\nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r  Erasing    : httpd-2.2.15-29.el6.centos.x86_64                            1/1 \n\r  Verifying  : httpd-2.2.15-29.el6.centos.x86_64                            1/1 \n\nRemoved:\n  httpd.x86_64 0:2.2.15-29.el6.centos                                           \n\nComplete!\n"
    ]
}

192.168.100.132 | success >> {
    "changed": true, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: fastestmirror, refresh-packagekit, security\nSetting up Remove Process\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.2.15-47.el6.centos.3 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.2.15-47.el6.centos.3        @updates        2.9 M\n\nTransaction Summary\n================================================================================\nRemove        1 Package(s)\n\nInstalled size: 2.9 M\nDownloading Packages:\nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r  Erasing    : httpd-2.2.15-47.el6.centos.3.x86_64                          1/1 \n\r  Verifying  : httpd-2.2.15-47.el6.centos.3.x86_64                          1/1 \n\nRemoved:\n  httpd.x86_64 0:2.2.15-47.el6.centos.3                                         \n\nComplete!\n"
    ]
}

[[email protected] ~]#

模块 service :

[[email protected] ~]# ansible-doc -s service
less 436
Copyright (C) 1984-2009 Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less
- name: M a n a g e   s e r v i c e s .
  action: 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=                  # 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 
      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 beha
      state                  # `started‘/`stopped‘ are idempotent actions that will not run commands unless necessary.  `restarted‘ will always bounce the service.  `r
[[email protected] ~]#

启动 httpd 服务,并设置开机启动

[[email protected] ~]# ansible testservers -m yum -a ‘name=httpd state=present‘

[[email protected] ~]# ansible testservers -m command -a ‘service httpd status‘
192.168.100.131 | FAILED | rc=3 >>
httpd 已停

192.168.100.132 | FAILED | rc=3 >>
httpd 已停

[[email protected] ~]# ansible testservers -m command -a ‘chkconfig --list httpd‘
192.168.100.131 | success | rc=0 >>
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off

192.168.100.132 | success | rc=0 >>
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off

[[email protected] ~]# ansible testservers -m service -a ‘name=httpd enabled=true state=started‘
192.168.100.131 | success >> {
    "changed": true, 
    "enabled": true, 
    "name": "httpd", 
    "state": "started"
}

192.168.100.132 | success >> {
    "changed": true, 
    "enabled": true, 
    "name": "httpd", 
    "state": "started"
}

[[email protected] ~]# ansible testservers -m command -a ‘service httpd status‘
192.168.100.131 | success | rc=0 >>
httpd (pid  3270) 正在运行...

192.168.100.132 | success | rc=0 >>
httpd (pid  33341) 正在运行...

[[email protected] ~]# ansible testservers -m command -a ‘chkconfig --list httpd‘
192.168.100.131 | success | rc=0 >>
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

192.168.100.132 | success | rc=0 >>
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

[[email protected] ~]#

模块 setup : 收集远程主机的信息

每个被管理的主机,在执行命令操作前都会执行setup模块,将信息汇报到ansible server 端

[[email protected] ~]#  ansible-doc -s setup
less 436
Copyright (C) 1984-2009 Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less
- name: G a t h e r s   f a c t s   a b o u t   r e m o t e   h o s t s
  action: 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 f
      filter                 # if supplied, only return facts that match this shell-style (fnmatch) wildcard.
[[email protected] ~]#

以 testservers 组中的192.168.100.132 主机为例:

192.168.100.132 | success >> {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.100.132"
        ], 
        "ansible_all_ipv6_addresses": [
            "fe80::20c:29ff:fe42:3d4b"
        ], 
        "ansible_architecture": "x86_64", 
        "ansible_bios_date": "07/31/2013", 
        "ansible_bios_version": "6.00", 
        "ansible_cmdline": {
            "KEYBOARDTYPE": "pc", 
            "KEYTABLE": "us", 
            "LANG": "zh_CN.UTF-8", 
            "nomodeset": true, 
            "quiet": true, 
            "rd_LVM_LV": "vg_v3/lv_swap", 
            "rd_NO_DM": true, 
            "rd_NO_LUKS": true, 
            "rd_NO_MD": true, 
            "rhgb": true, 
            "ro": true, 
            "root": "/dev/mapper/vg_v3-lv_root"
        }, 
        "ansible_date_time": {
            "date": "2016-02-29", 
            "day": "29", 
            "epoch": "1456726561", 
            "hour": "14", 
            "iso8601": "2016-02-29T06:16:01Z", 
            "iso8601_micro": "2016-02-29T06:16:01.657953Z", 
            "minute": "16", 
            "month": "02", 
            "second": "01", 
            "time": "14:16:01", 
            "tz": "CST", 
            "tz_offset": "+0800", 
            "weekday": "Monday", 
            "year": "2016"
        }, 
        "ansible_default_ipv4": {
            "address": "192.168.100.132", 
            "alias": "eth0", 
            "gateway": "192.168.100.2", 
            "interface": "eth0", 
            "macaddress": "00:0c:29:42:3d:4b", 
            "mtu": 1500, 
            "netmask": "255.255.255.0", 
            "network": "192.168.100.0", 
            "type": "ether"
        }, 
        "ansible_default_ipv6": {}, 
        "ansible_devices": {
            "sda": {
                "holders": [], 
                "host": "SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)", 
                "model": "VMware Virtual S", 
                "partitions": {
                    "sda1": {
                        "sectors": "1024000", 
                        "sectorsize": 512, 
                        "size": "500.00 MB", 
                        "start": "2048"
                    }, 
                    "sda2": {
                        "sectors": "40916992", 
                        "sectorsize": 512, 
                        "size": "19.51 GB", 
                        "start": "1026048"
                    }
                }, 
                "removable": "0", 
                "rotational": "1", 
                "scheduler_mode": "cfq", 
                "sectors": "41943040", 
                "sectorsize": "512", 
                "size": "20.00 GB", 
                "support_discard": "0", 
                "vendor": "VMware,"
            }, 
            "sr0": {
                "holders": [], 
                "host": "SATA controller: VMware SATA AHCI controller", 
                "model": "VMware SATA CD01", 
                "partitions": {}, 
                "removable": "1", 
                "rotational": "1", 
                "scheduler_mode": "cfq", 
                "sectors": "2097151", 
                "sectorsize": "512", 
                "size": "1024.00 MB", 
                "support_discard": "0", 
                "vendor": "NECVMWar"
            }
        }, 
        "ansible_distribution": "CentOS", 
        "ansible_distribution_major_version": "6", 
        "ansible_distribution_release": "Final", 
        "ansible_distribution_version": "6.5", 
        "ansible_domain": "bta.net.cn", 
        "ansible_env": {
            "CVS_RSH": "ssh", 
            "G_BROKEN_FILENAMES": "1", 
            "HOME": "/root", 
            "LANG": "C", 
            "LC_CTYPE": "C", 
            "LESSOPEN": "|/usr/bin/lesspipe.sh %s", 
            "LOGNAME": "root", 
            "MAIL": "/var/mail/root", 
            "PATH": "/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin", 
            "PWD": "/root", 
            "QTDIR": "/usr/lib64/qt-3.3", 
            "QTINC": "/usr/lib64/qt-3.3/include", 
            "QTLIB": "/usr/lib64/qt-3.3/lib", 
            "SHELL": "/bin/bash", 
            "SHLVL": "2", 
            "SSH_ASKPASS": "/usr/libexec/openssh/gnome-ssh-askpass", 
            "SSH_CLIENT": "192.168.100.129 46085 22", 
            "SSH_CONNECTION": "192.168.100.129 46085 192.168.100.132 22", 
            "SSH_TTY": "/dev/pts/0", 
            "TERM": "vt100", 
            "USER": "root", 
            "_": "/usr/bin/python"
        }, 
        "ansible_eth0": {
            "active": true, 
            "device": "eth0", 
            "ipv4": {
                "address": "192.168.100.132", 
                "netmask": "255.255.255.0", 
                "network": "192.168.100.0"
            }, 
            "ipv6": [
                {
                    "address": "fe80::20c:29ff:fe42:3d4b", 
                    "prefix": "64", 
                    "scope": "link"
                }
            ], 
            "macaddress": "00:0c:29:42:3d:4b", 
            "module": "e1000", 
            "mtu": 1500, 
            "promisc": false, 
            "type": "ether"
        }, 
        "ansible_fips": false, 
        "ansible_form_factor": "Other", 
        "ansible_fqdn": "bt-199-037.bta.net.cn", 
        "ansible_hostname": "v3", 
        "ansible_interfaces": [
            "lo", 
            "pan0", 
            "eth0"
        ], 
        "ansible_kernel": "2.6.32-431.el6.x86_64", 
        "ansible_lo": {
            "active": true, 
            "device": "lo", 
            "ipv4": {
                "address": "127.0.0.1", 
                "netmask": "255.0.0.0", 
                "network": "127.0.0.0"
            }, 
            "ipv6": [
                {
                    "address": "::1", 
                    "prefix": "128", 
                    "scope": "host"
                }
            ], 
            "mtu": 16436, 
            "promisc": false, 
            "type": "loopback"
        }, 
        "ansible_lsb": {
            "codename": "Final", 
            "description": "CentOS release 6.5 (Final)", 
            "id": "CentOS", 
            "major_release": "6", 
            "release": "6.5"
        }, 
        "ansible_machine": "x86_64", 
        "ansible_machine_id": "7fa908076135396c09ba795100000011", 
        "ansible_memfree_mb": 217, 
        "ansible_memory_mb": {
            "nocache": {
                "free": 640, 
                "used": 348
            }, 
            "real": {
                "free": 217, 
                "total": 988, 
                "used": 771
            }, 
            "swap": {
                "cached": 0, 
                "free": 1981, 
                "total": 1983, 
                "used": 2
            }
        }, 
        "ansible_memtotal_mb": 988, 
        "ansible_mounts": [
            {
                "device": "/dev/mapper/vg_v3-lv_root", 
                "fstype": "ext4", 
                "mount": "/", 
                "options": "rw", 
                "size_available": 13751066624, 
                "size_total": 18569568256, 
                "uuid": "5b1e1ab5-6a12-4466-a832-0fa80ec05610"
            }, 
            {
                "device": "/dev/sda1", 
                "fstype": "ext4", 
                "mount": "/boot", 
                "options": "rw", 
                "size_available": 445854720, 
                "size_total": 507744256, 
                "uuid": "01b79867-8bb5-4492-bc99-ee4c1e77ad45"
            }
        ], 
        "ansible_nodename": "v3.lansgg.com", 
        "ansible_os_family": "RedHat", 
        "ansible_pan0": {
            "active": false, 
            "device": "pan0", 
            "id": "8000.000000000000", 
            "interfaces": [], 
            "macaddress": "82:5d:e7:15:7f:60", 
            "mtu": 1500, 
            "promisc": false, 
            "stp": false, 
            "type": "bridge"
        }, 
        "ansible_pkg_mgr": "yum", 
        "ansible_processor": [
            "GenuineIntel", 
            "Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz"
        ], 
        "ansible_processor_cores": 1, 
        "ansible_processor_count": 1, 
        "ansible_processor_threads_per_core": 1, 
        "ansible_processor_vcpus": 1, 
        "ansible_product_name": "VMware Virtual Platform", 
        "ansible_product_serial": "VMware-56 4d 4b fa 62 36 82 17-59 18 88 5d 7e 42 3d 4b", 
        "ansible_product_uuid": "564D4BFA-6236-8217-5918-885D7E423D4B", 
        "ansible_product_version": "None", 
        "ansible_python_version": "2.6.6", 
        "ansible_selinux": {
            "status": "disabled"
        }, 
        "ansible_ssh_host_key_dsa_public": "AAAAB3NzaC1kc3MAAACBAJvg4oIca9Wzg59BbkQv4fP2b0e/e6Er5AwKb7fe2NC5pIBYDZFum68IJcIwrjb1WalwMXJtRl6OxPq3dO+D7RDitATv8z8N4eviAbOwg8zlSYcadazYcElSBYaWfvuSH+PoNuLc3KwL6S45vNnXjJRA40QALWYPCKNBn/g1Lqc/AAAAFQD9+juFm6jft2mUEB8+H7wu+IrtMQAAAIEAi2RsOt4Svr8G4nLgZhzMeegq6zNZm2IPDDjLIK6Hk0dMqLGjNsJ9muUX9NRnRj4UVmon4LuMU6Z/fXag5UhbUUHRftLf9tplGR5CX0MtQplDvBHiB+KXu9l1hzaFgRW+oZMVsaFTEox+4lQBLSjVjX/3vALpnGYdkheN6nU4FEMAAACANQMb+9zNptx3s1ohb9mFJmG9MKVP8IXY3VNZqCSHVlmIp3p1kepNH6sKZDyo22SFO0l0rXP9hADxwlhvhxOyupnDmpsM1Ar5vFxusgZgGisPzOtljQbzeuXlCo+SUswEoxS4NY/CSP8Gc8eZD+JAcS+pDuBxQckC8JIDfOstlS4=", 
        "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAABIwAAAQEAzM8GNFPLJTd+3PYOlj5wcJMYgZNIdN7ozvQVZn8O7CpDnBXscGBezQ1m2QJsrzeTWR2FOKrAqv3oWeFwW65cxcSgVgdzVHatR6KhVqqJyF0+39sRAAAxAwK3vXK2IdKLLIIWShvIH+F0uL9aNP0UQt0gJLsqVI6yJ1zAB3qexPX+bZNRa3K33tkeAWfJdlJUScgaUe3oUnvAdXMBuTYp9fJwZyMo3HibUuE2YbeFAXTj6qnRyKOgwponPkkv9TuM8yenNIKqbjxIALgNyERMx0FDHc22Ow2AEfWASE+KT8ZrdbjKl+pMUz64MAHpaNgWzrivuSFRUzjrECwFolk47w==", 
        "ansible_swapfree_mb": 1981, 
        "ansible_swaptotal_mb": 1983, 
        "ansible_system": "Linux", 
        "ansible_system_vendor": "VMware, Inc.", 
        "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", 
        "module_setup": true
    }, 
    "changed": false
}

[[email protected] ~]#

一般在 playbook 中使用较多,如template模块文件中。

时间: 2024-10-06 01:10:47

ansible模块yum、services、setup的相关文章

ansible 模块

一.什么是ansible 什么是ansible?官方的title是"Ansibleis Simple IT Automation"->简单的自动化IT工具.ansible功能:自动化部署APP:自动化管理配置项:自动化的持续交付:自动化的(AWS)云服务管理.其本质就是在一个台或者几台服务器上,批量的执行命令. fabric和ansible有什么差别呢?简单来说fabric像是一个工具箱,提供了很多好用的工具,用来在Remote执行命令,而ansible则是提供了一套简单的流程,

ansible 模块学习

Ansible通过模块的方式来完成一些远程的管理工作.可以通过ansible-doc -l查看所有模块,可以使用ansible-doc -s module来查看某个模块的参数,也可以使用ansible-doc help module来查看该模块更详细的信息.默认的模块位置在/usr/share/ansible.下面列出一些常用的模块: 1. setup 可以用来查看远程主机的一些基本信息: ansible -i /etc/ansible/hosts test -m setup 2.ping 可以

ansible模块command、shell、raw、script

环境: ansible端: ip:192.168.100.129 hostname:node1.lansgg.com client端: ip:192.168.100.131 hostname:v2.lansgg.com ip:192.168.100.132 hostname:v3.lansgg.com [[email protected] ansible]# pwd /etc/ansible [[email protected] ansible]# cat hosts [testservers]

第4天:Ansible模块

Ansible对远程服务器的实际操作实际是通过模块完成的,其工作原理如下: 1)将模块拷贝到远程服务器 2)执行模块定义的操嘴,完成对服务器的修改 3)在远程服务器中删除模块 需要说明的是,Ansible中的模块是幂等的.也就是说,多次执行相同的操作,只有第一次会起作用.这也是在编写自定义Ansible模块的需要注意的地方. Ansible提供了大量的模块,ansible-doc命令用于在命令行查看模块列表,也可以使用该工具在命令行获取模块帮助信息 ansible-doc -l 下面命令用户获取

ansible之yum模块

其实这些东西,包括之前的都是很早以前的东东了,就是怕忘记了,记录一下.到时候可以翻翻看,因为第一次接触的时候感觉上手挺快的,都是封装好的.. 比如有一组机器需要安装vim,那么不能一个一个服务器上ssh然后执行yum install vim -y.少的话还阔以,多的话,呵呵.. yum模块用法 [[email protected] ~]# ansible-doc -s yum less 436 Copyright (C) 1984-2009 Mark Nudelman less comes wi

ansible模块批量管理

1.[copy]模块 ansible oldboy-m copy -a "src=/etc/hosts dest=/opt/" 加上backup=yes对客户端的文件进行备份 ansible oldboy -m copy -a "src=/etc/hostsdest=/opt/ backup=yes" 2.Shell模块 用之前需要将脚本先推送到客户端才能执行 1)推送 ansible oldboy-m copy -a "src=/server/scrip

ansible模块

1./etc/ansible/hosts 文件配置如下: [group01] //ubuntu16 jumper ansible_ssh_port=6666 ansible_ssh_host=172.16.1.206 172.16.1.207 [group01] //centos7 172.16.1.201 2.远程重启服务 sudo ansible group01 –m service –a "name=ssh state=restarted" 3.查看远程主机名 sudo ansi

ansible模块简介

http://openskill.cn/article/130 以上链接是详细介绍 一.copy模块 把主控端文件拷贝到指定节点上:ansible 主机名 -m copy -a 'src=/原路径 dest=/目标路径' 二.file模块 目的:更改指定节点文件属性 ansible 主机名file -a  "dest=/目标路径 mode=755" 其中mode是修改目标路径的属性 三.cron模块 目的:定义计划任务(每三分钟到主机更新一次时间) ansible all -m cro

Import-Module ServerManager Import-Module : 未能加载指定的模块“ServerManager”,因为在任何模块目录中都没有找到有效模块文件...(通过Setup Factory调用PowerShell的脚本)

操作系统: Windows server 2008 R2(64位) C:\Windows\System32\WindowsPowerShell\v1.0\Modules 下有ServerManager的东东,可是还是找不到. 解决这个问题,需要2步: 1.Powershell中的执行策略(Execution Policy) 原因一个是因为Powershell默认的执行策略是Restricted,即可以运行单条命令,但不能运行脚本,包括格式和配置文件 (.ps1xml).模块脚本文件 (.psm1