🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# yum和service模块 ## 软件管理模块[yum](http://docs.ansible.com/ansible/yum_module.html) ### 在命令行使用yum模块安装 ``` ansible node2.test.com -m yum -a 'name=httpd' ``` ### 选项 ### 在playbook中这样使用 ``` --- - name: yum test hosts: b1.hi.com tasks: - name: yum install pkg yum: name={{ item }} update_cache=True with_items: - git - vim-enhanced - tree - screen # 更新所有软件 - name: upgrade pkg yum: updade_cache=yes upgrade=yes ``` ### 示例 ``` - name: install the latest version of Apache yum: name: httpd state: latest - name: remove the Apache package yum: name: httpd state: absent - name: install the latest version of Apache from the testing repo yum: name: httpd enablerepo: testing state: present - name: install one specific version of Apache yum: name: httpd-2.2.29-1.4.amzn1 state: present - name: upgrade all packages yum: name: '*' state: latest - name: install the nginx rpm from a remote repo yum: name: http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm state: present - name: install nginx rpm from a local file yum: name: /usr/local/src/nginx-release-centos-6-0.el6.ngx.noarch.rpm state: present - name: install the 'Development tools' package group yum: name: "@Development tools" state: present - name: install the 'Gnome desktop' environment group yum: name: "@^gnome-desktop-environment" state: present - name: List ansible packages and register result to print with debug later. yum: list: ansible ``` - - - - - - ## 服务管理[service](http://docs.ansible.com/ansible/service_module.html) ### 选项 ### 在命令行使用方式 ``` ansible node2.test.com -m service -a 'name=httpd state=started enabled=true' ansible node2.test.com -m service -a 'name=network state=restarted args=eth0' ``` ### 示例 ``` # Example action to start service foo, based on running process /usr/bin/foo - service: name: foo pattern: /usr/bin/foo state: started # Example action to restart network service for interface eth0 - service: name: network state: restarted args: eth0 ```