6、ansible-Ad-Hoc-点对点模式--m yum-软件包模块
查文档:ansible-doc yum
升级所有的包:不建议使用,耗时长
·· ansible host1 -m yum -a 'name=* state=latest'
安装apache
ansible webserver -m yum -a 'name=httpd state=latest'
·· webserver 是一个组 组下面有host1-host4四台主机
删除软件包
ansible webserver -m yum -a 'name=vsftpd state=removed'
ansible webserver -m yum -a 'name=vsftpd state=absent'
state=removed
和 state=absent
两个参数都可以用来卸载软件包。它们的区别在于:
-
state=removed
:表示将软件包及其所有依赖项从系统中完全删除。这将删除软件包及其配置文件、日志文件和其他相关文件。如果您想要完全删除软件包及其所有相关文件,可以使用state=removed
参数。 -
state=absent
:表示将软件包从系统中卸载,但不会删除软件包的配置文件、日志文件和其他相关文件。如果您只想卸载软件包,但保留其配置文件和其他相关文件,可以使用state=absent
参数。