ansible的ad-hoc搭建http

命令
ansible-doc -l ##可以显示所有可用模块

[devops@server4 ansible]$ vim inventory 
[devops@server4 ansible]$ cat inventory 
[test]
172.25.2.105
172.25.2.106

[web]
172.25.2.106

[devops@server4 ansible]$ vim ansible.cfg 
[devops@server4 ansible]$ cat ansible.cfg 
[defaults]
inventory=./inventory
remote user=devops

[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False

[devops@server4 ansible]$ ansible 'test:&web' -m ping  ##查看两组的交集
172.25.2.106 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
[devops@server4 ansible]$ ansible 'test:!web' -m ping  ##查看两组不同的
172.25.2.105 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
[devops@server4 ansible]$ ansible 'web' -m yum -a "name=httpd state=present"  ##给web组安装http阿帕奇
172.25.2.106 | CHANGED => {
    "ansible_facts": {
        "pkg_mgr": "yum"
    }, 
    "changed": true, 
    "msg": "", 
    "rc": 0, 
    "results": [
        "Loaded plugins: product-id, search-disabled-repos, subscription-manager\nThis system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.\nResolving Dependencies\n--> Running transaction check\n---> Package httpd.x86_64 0:2.4.6-45.el7 will be installed\n--> Processing Dependency: httpd-tools = 2.4.6-45.el7 for package: httpd-2.4.6-45.el7.x86_64\n--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-45.el7.x86_64\n--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.x86_64\n--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.x86_64\n--> Running transaction check\n---> Package apr.x86_64 0:1.4.8-3.el7 will be installed\n---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed\n---> Package httpd-tools.x86_64 0:2.4.6-45.el7 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-45.el7          rhel7.3         1.2 M\nInstalling for dependencies:\n apr                 x86_64         1.4.8-3.el7           rhel7.3         103 k\n apr-util            x86_64         1.5.2-6.el7           rhel7.3          92 k\n httpd-tools         x86_64         2.4.6-45.el7          rhel7.3          84 k\n mailcap             noarch         2.1.41-2.el7          rhel7.3          31 k\n\nTransaction Summary\n================================================================================\nInstall  1 Package (+4 Dependent packages)\n\nTotal download size: 1.5 M\nInstalled size: 4.3 M\nDownloading packages:\n--------------------------------------------------------------------------------\nTotal                                               11 MB/s | 1.5 MB  00:00     \nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Installing : apr-1.4.8-3.el7.x86_64                                       1/5 \n  Installing : apr-util-1.5.2-6.el7.x86_64                                  2/5 \n  Installing : httpd-tools-2.4.6-45.el7.x86_64                              3/5 \n  Installing : mailcap-2.1.41-2.el7.noarch                                  4/5 \n  Installing : httpd-2.4.6-45.el7.x86_64                                    5/5 \n  Verifying  : httpd-tools-2.4.6-45.el7.x86_64                              1/5 \n  Verifying  : apr-util-1.5.2-6.el7.x86_64                                  2/5 \n  Verifying  : mailcap-2.1.41-2.el7.noarch                                  3/5 \n  Verifying  : httpd-2.4.6-45.el7.x86_64                                    4/5 \n  Verifying  : apr-1.4.8-3.el7.x86_64                                       5/5 \n\nInstalled:\n  httpd.x86_64 0:2.4.6-45.el7                                                   \n\nDependency Installed:\n  apr.x86_64 0:1.4.8-3.el7                 apr-util.x86_64 0:1.5.2-6.el7       \n  httpd-tools.x86_64 0:2.4.6-45.el7        mailcap.noarch 0:2.1.41-2.el7       \n\nComplete!\n"
    ]
}
[devops@server4 ansible]$ ansible 'web' -m service -a "name=httpd state=started"  ##开启httpd

你可能感兴趣的:(ansible的ad-hoc搭建http)