SQL Server database queries in Ansible(Ansible 中的 SQL Server 数据库查询)
问题描述
我想知道社区中是否有人使用 Ansible 操作过 Microsoft SQL Server 数据库?
I would like to find out if anyone in the community has used Ansible to manipulate a Microsoft SQL Server database?
我们想向我们用 Ansible 编写的环境配置脚本添加一个任务,该脚本将 INSERT
行插入到 SQL Server 表中.这些行将具有在我们的变量文件中指定的参数.
We want to add a task to our environment configuration scripts written in Ansible that will INSERT
rows into a SQL Server table. The rows will have parameters that are specified in our variables files.
我一直无法找到实现此目的的特定 Ansible 模块,所以想听听是否有人在其他方面取得了成功?
I have been unable to locate a specific Ansible module for achieving this so would like to hear if anyone has has success in some other way?
推荐答案
为了完整起见,这里是 Ansible to SELECT & 中使用的解决方案的语法.插入 Microsoft SQL Server:
For completeness here is the syntax of the solution used in Ansible to SELECT & INSERT for Microsoft SQL Server:
插入
- name: 'insert row to SQL server DB'
win_shell: "invoke-sqlcmd -username \"{{db_user}}\" -password \"{{db_pass}}\" -Query \"INSERT INTO Addresses (DoorNum,Street,Town,PostCode) VALUES ({{ item.doornum }},'{{ item.street }}','{{ item.town }}''{{ item.postcode }}')\""
选择
- name: 'select from SQL server DB'
win_shell: "invoke-sqlcmd -username \"{{db_user}}\" -password \"{{db_pass}}\" -Query \"SELECT ID FROM Addresses WHERE PostCode = '{{ item.postcode }}'\" | Select-Object * -ExcludeProperty ItemArray, Table, RowError, RowState, HasErrors | ConvertTo-Json"
register: response
- set_fact:
ids: "{{ response.stdout|from_json}}"
- debug:
var: ids
这篇关于Ansible 中的 SQL Server 数据库查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Ansible 中的 SQL Server 数据库查询


基础教程推荐
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01