标签:copy 安装 工具 des directory down mon 运行命令 root
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) ansible被控端: 192.168.10.144: [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 192.168.10.143: [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
[web] #主机组 192.168.10.144 ansible_ssh_user=root ansible_ssh_pass=123 #主机的用户名和密码,如果不是公钥验证,也可以尝试密码连接 192.168.10.145 [mysql] 47.94.20.198
[root@localhost ansible]# ansible web -a ‘chdir=/home ls‘ 192.168.10.145 | SUCCESS | rc=0 >> 192.168.10.144 | SUCCESS | rc=0 >> abc1 abc2 abc3
[root@localhost ~]# ansible web -m file -a ‘path=/tmp/test.txt state=touch‘
192.168.10.145 | SUCCESS => {
"changed": true,
"dest": "/tmp/test.txt",
"gid": 0,
"group": "root",
"mode": "0644",
"owner": "root",
"size": 0,
"state": "file",
"uid": 0
}
192.168.10.144 | SUCCESS => {
"changed": true,
"dest": "/tmp/test.txt",
"gid": 0,
"group": "root",
"mode": "0644",
"owner": "root",
"secontext": "unconfined_u:object_r:user_tmp_t:s0",
"size": 0,
"state": "file",
"uid": 0
[root@localhost ~]# ansible web -m file -a ‘path=/tmp/test_dir state=directory owner=root group=root mode=777‘
192.168.10.145 | SUCCESS => {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0777",
"owner": "root",
"path": "/tmp/test_dir",
"size": 6,
"state": "directory",
"uid": 0
}
192.168.10.144 | SUCCESS => {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0777",
"owner": "root",
"path": "/tmp/test_dir",
"secontext": "unconfined_u:object_r:user_tmp_t:s0",
"size": 6,
"state": "directory",
"uid": 0
}
root@localhost ~]# ansible web -m service -a "name=postfix state=started enabled=yes"
ansible web -s cron -a "minute=0 hour=3 job=‘/bin/sh /mnt/shell/hostname.sh‘ name=check hostname"
ansible web -m yum -a ‘name=libselinux-python state=installed‘
yum卸载软件:
[root@localhost ~]# ansible web -m yum -a ‘name=lrzsz state=removed‘
192.168.10.145 | SUCCESS => {
"changed": false,
"msg": "",
"rc": 0,
"results": [
"lrzsz is not installed"
]
}
192.168.10.144 | SUCCESS => {
"changed": true,
"msg": "",
"rc": 0,
"results": [
"已加载插件:fastestmirror, langpacks\n正在解决依赖关系\n--> 正在检查事务\n---> 软件包 lrzsz.x86_64.0.0.12.20-36.el7 将被 删除\n--> 解决依赖关系完成\n\n依赖关系解决\n\n================================================================================\n Package 架构 版本 源 大小\n================================================================================\n正在删除:\n lrzsz x86_64 0.12.20-36.el7 @base 181 k\n\n事务概要\n================================================================================\n移除 1 软件包\n\n安装大小:181 k\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n 正在删除 : lrzsz-0.12.20-36.el7.x86_64 1/1 \n 验证中 : lrzsz-0.12.20-36.el7.x86_64 1/1 \n\n删除:\n lrzsz.x86_64 0:0.12.20-36.el7 \n\n完毕!\n"
]
}
标签:copy 安装 工具 des directory down mon 运行命令 root
原文地址:https://www.cnblogs.com/wenwei-blog/p/9065040.html