概述
ansible執(zhí)行mysql腳本
實(shí)踐
官網(wǎng)文檔
環(huán)境要求
環(huán)境需要安裝以下內(nèi)容:
- 1.mysql客戶(hù)端(安裝了mysql即會(huì)有)
- 2.安裝MySQL-python (Python 2.X)
詳細(xì)插件安裝鏈接
ansible yml腳本
關(guān)鍵代碼如下:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-855251.html
# 劇本集
- 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 [打印調(diào)試信息] **********************************************************************************************************************************************************************
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
離線包
下載鏈接文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-855251.html
到了這里,關(guān)于ansible執(zhí)行mysql腳本的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!