ansible执行mysql脚本
概述
ansible执行mysql脚本
实践
环境要求
环境需要安装以下内容:
- 1.mysql客户端(安装了mysql即会有)
- 2.安装MySQL-python (Python 2.X)
详细插件安装链接
ansible yml脚本
关键代码如下:
# 剧本集
- hosts: nodes
gather_facts: false
tasks:
- name: Run pwd command and capture the output
shell: pwd
register: pwd_current_path
- name: nacos sql init
mysql_db:
login_host: "{{ mysql_url }}"
login_user: "{{ mysql_user }}"
login_password: "{{ mysql_password }}"
login_port: 3306
name: ry-config
state: import
target: ./ry_config.sql
命令
# ansible-playbook release.yml --extra-vars "version=1.23.45 other_variable=foo"
ansible-playbook -i hosts main.yaml --extra-vars "mysql_url=10.57.12.18 mysql_user=root mysql_password=root"
[root@ks2p-hadoop01 ansible-test]# ls
hosts main.yaml PyMySQL-1.0.2-py3-none-any.whl ry_config_20220929.sql
[root@ks2p-hadoop01 ansible-test]# ansible-playbook -i hosts main.yaml --extra-vars "mysql_url=10.57.12.18 mysql_user=root mysql_password=root"
PLAY [nodes] ***********************************************************************************************************************************************************************
TASK [打印调试信息] **********************************************************************************************************************************************************************
ok: [ks2p-hadoop04] => {
"msg": "hello"
}
TASK [nacos mysql sql init] ********************************************************************************************************************************************************
changed: [ks2p-hadoop04]
PLAY RECAP *************************************************************************************************************************************************************************
ks2p-hadoop04 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
离线包
原文地址:https://blog.csdn.net/2301_79691134/article/details/137918529
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!