企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 软件管理模块[yum][1] ### 在命令行使用yum模块安装 ``` ansible node2.test.com -m yum -a 'name=httpd' ``` ### 选项 ![](http://om4h63cja.bkt.clouddn.com/17-7-11/66745584.jpg) ### 在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][2] ### 选项 ![](http://om4h63cja.bkt.clouddn.com/17-7-12/95013435.jpg) ### 在命令行使用方式 ``` 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 ~~~ [1]:http://docs.ansible.com/ansible/yum_module.html [2]:http://docs.ansible.com/ansible/service_module.html