1、在group1的被管理机里的mariadb里创建一个abc库;
1)
然后我们到agent主机上进行检查:
可以看到数据库已经创建成功。
再看几个其他命令:
#a组主机重启mysql,并设置开机自启
ansible a -m service -a "name=mysql enabled=yes state=restarted"
script模块:
script模块用于在远程主机上执行本地脚本。
脚本在master上,但是可以在agent服务器上执行。
[root@localhost ~]# cat /tmp/1.sh
#!/bin/bash
yum install -y mariadb-server &> /dev/null
systemctl start mariadb
systemctl enable mariadb
mysql << EOF
create database abc;
quit
EOF
说明:上面这个创建数据库的方法可以参考下。
[root@localhost ~]# ansible group1 -m script -a "/tmp/1.sh"
192.168.17.105 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 192.168.17.105 closed.\r\n",
"stderr_lines": [
"Shared connection to 192.168.17.105 closed."
],
"stdout": "Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.\r\n",
"stdout_lines": [
"Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service."
]
}
192.168.17.106 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to 192.168.17.106 closed.\r\n",
"stderr_lines": [
"Shared connection to 192.168.17.106 closed."
],
"stdout": "Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.\r\n",
"stdout_lines": [
"Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service."
]
}
执行结果:
文章来源:https://www.toymoban.com/news/detail-684710.html
Shell能解决的,可以通过这种方式来解决的。学完Python比Shell严谨点。Shell有点天马行空的解决。文章来源地址https://www.toymoban.com/news/detail-684710.html
到了这里,关于Ansible学习笔记10的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!