Ansible学习笔记9

yum_repository模块:

yum_repository模块用于配置yum仓库的。

测试下:

bash 复制代码
[root@localhost ~]# ansible group1 -m yum_repository -a "name=local description=localyum baseurl=file:///mnt/ enabled=yes gpgcheck=no"
192.168.17.106 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "repo": "local",
    "state": "present"
}
192.168.17.105 | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": true,
    "repo": "local",
    "state": "present"
}

检查:

bash 复制代码
[root@agent1 yum.repos.d]# ll
total 52
-rw-r--r-- 1 root root 1664 Aug 30 13:06 CentOS-Base.repo
-rw-r--r-- 1 root root 1309 Aug 30 13:06 CentOS-CR.repo
-rw-r--r-- 1 root root  649 Aug 30 13:06 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root  314 Aug 30 13:06 CentOS-fasttrack.repo
-rw-r--r-- 1 root root  630 Aug 30 13:06 CentOS-Media.repo
-rw-r--r-- 1 root root 1331 Aug 30 13:06 CentOS-Sources.repo
-rw-r--r-- 1 root root 8515 Aug 30 13:06 CentOS-Vault.repo
-rw-r--r-- 1 root root  616 Aug 30 13:06 CentOS-x86_64-kernel.repo
-rw-r--r-- 1 root root  951 Aug 30 13:06 epel.repo
-rw-r--r-- 1 root root 1050 Aug 30 13:06 epel-testing.repo
-rw-r--r-- 1 root root   73 Aug 30 15:04 local.repo
[root@agent1 yum.repos.d]# cat local.repo
[local]
baseurl = file:///mnt/
enabled = 1
gpgcheck = 0
name = localyum

yum模块(重点):

yum模块用于使用yum命令来实现软件包的安装与卸载。

使用yum安装一个软件(前提:group1的yum配置都已经OK)

检查agent机器,看到vsftpd都已经安装成功。

使用yum模块安装httpd、httpd-devel,state=latest表示安装的最新版本。

可以检查到安装进度:

检查各个agent机器,发现httpd都已经安装。

到agent1机器上检查,看到httpd已经卸载。

bash 复制代码
[root@agent1 yum.repos.d]# rpm -ql httpd
package httpd is not installed

Service模块(重点):

启动vsftpd,并设置为开机自动启动。

停止vsftpd服务,然后关闭开机自动启动。

配置这块内容,就直接用copy模块,将配置文件复制过去。

相关推荐
chairon3 天前
Ansible:playbook的高级用法
linux·运维·服务器·ansible·apache
树下一少年3 天前
ansible+docker+docker-compose快速部署4节点高可用minio集群
docker·容器·ansible·docker-compose·minio集群
千航@abc5 天前
Ansible 实战:Roles,运维的 “魔法函数”
ansible·playbook·roles·角色·模版·剧本
一个高效工作的家伙5 天前
ansible可视化自动化平台-semaphore
ansible
树下一少年5 天前
通过ansible+docker-compose快速安装一主两从redis+三sentinel
redis·docker·ansible·sentinel·docker-compose
独隅6 天前
针对Ansible执行脚本时报错“可执行文件格式错误”,以下是详细的解决步骤和示例
运维·开发语言·ansible·lua·lua5.4
大小科圣6 天前
Ansible playbook
ansible
大小科圣6 天前
ansible条件判断及循环
ansible
狂奔solar8 天前
ansible-playbook 写arm版达梦7数据库的一键安装脚本
ansible
晴天Y288 天前
ansible角色 role
ansible