ansible - 如何在 Windows 上将 Keycloak Admin CLI 与 Ansible 一起使用
问题描述
我在 Windows 2016 服务器上安装了 Keycloak 并通过 Ansible 创建了一个管理员用户,到目前为止一切顺利。现在我想通过 Ansible 安装 Admin API,以便也通过 Ansible 配置 Keycloak。当我在 Windows 机器的命令行中本地运行接下来的 3 个命令时,一切正常: 1. 安装 API:kcadm.bat
从 bin 文件夹运行
连接到 api:
\bin>kcadm config credentials --server http://localhost:8080/auth --realm master --user keycloak
然后我被要求进行身份验证: Logging into http://localhost:8080/auth as user keycloak of realm master 输入密码: xxxxx创建客户端:
c:\> kcadm create clients -r master -s clientId=my-client-s "redirectUris=[\"http://localhost:8980/myapp/*\"]" -i > clientid.txt
谁能建议如何在 Ansible 中执行此操作?
我用 win 命令运行第一个命令:
- name: install admin cli for keycloak
win_command: 'C:\Install\Keycloak\keycloak-6.0.1\keycloak- 6.0.1\bin\kcadm.bat'
我正进入(状态:
fatal: [keykloak-ansible]: FAILED! => {"changed": true, "cmd": "C:\\Install\\Keycloak\\keycloak-6.0.1\\keycloak-6.0.1\\bin\\kcadm.bat", "delta": "0:00:01.190629", "end": "2019-05-16 06:42:36.617885", "msg": "non-zero return code", "rc": 1, "start": "2019-05-16 06:42:35.427256", "stderr": "", "stderr
_lines"
不确定 kcadm.bat 需要什么,因为从细节上看它没有安装任何东西。因此,我尝试立即运行身份验证命令,如下所示:
- name: keycloak cli authentication
win_command: kcadm config credentials --server http://10.128.32.220:8080/auth --realm master --user keycloak --password xxx
args:
chdir: 'C:\Install\Keycloak\keycloak-6.0.1\keycloak-6.0.1\bin'
但这失败了:
fatal: [keykloak-ansible]: FAILED! => {"changed": false, "cmd": "C:\\Install\\Keycloak\\keycloak-6.0.1\\keycloak-6.0.1\\bin\\kcadm config credentials --server http://10.128.32.220:8080/auth --realm master --user keycloak", "msg": "Exception calling \"SearchPath\" with \"1\" argument(s): \"Could not
locate the following executable C:\\Install\\Keycloak\\keycloak-6.0.1\\keycloak-6.0.1\\bin\\kcadm.exe
有人有建议吗?有人曾经在 Windows 上将 Admin CLI 与 Ansible 一起使用吗?
谢谢丽娜
解决方案
我也在尝试在 Windows 中实现相同的功能。我有一个服务提供者文件,它是一个 XML 文档。我想使用 keycloak CLI 创建客户端,但无法使用服务提供者 xml 文件创建客户端。虽然用于创建客户端的命令是:
kcadm.bat create clients -r demo -s clientId=adminconsole -s "redirectUris=[\"https://localhost:8080/admin-web/*\"]" -s protocol=saml
此命令正在创建客户端,但不像导入文件那样创建客户端。可能需要使用一些附加参数来提供更多信息,例如签名证书、加密证书等的值。
对于提出的问题,您可以使用:
名称:Keycloak 配置 - 创建领域、用户、客户端和设置用户密码
become_method: runas become: yes vars: ansible_become_user: "{{ ansible_user }}" ansible_become_pass: "{{ ansible_password }}" ansible.windows.win_command: cmd.exe args: chdir: '{{ keycloak_bin_path }}' stdin: "{{ item.From }}" loop: - { From: 'kcadm.bat config credentials --server https://localhost:8081/auth --realm master --user {{ keycloak_admin }} --password {{ keycloak_password }}' } - { From: 'kcadm.bat create realms -s realm={{ keycloak_realm }} -s enabled=true' } - { From: 'kcadm.bat create users -r {{ keycloak_realm }} -s username={{ keycloak_user }} -s enabled=true -o --fields id,username' } - { From: 'kcadm.bat set-password -r {{ keycloak_realm }} --username {{ keycloak_user }} --new-password {{ keycloak_user_pass }} -t' } - { From: 'kcadm.bat create clients -r {{ keycloak_realm }} -s clientId=adminconsole -s "redirectUris=[\"https://localhost:8080/admin-web/*"]" -s protocol=saml' }
推荐阅读
- javascript - 期望从 promise 分配的值(Jest unittest)
- amazon-web-services - 如何让 lambda 函数访问所有 SQS 队列?
- javascript - 如何从元素的样式中提取单个 CSS 过滤器功能?
- javascript - 如何在 Chartjs 的特定区域进行缩放和平移?
- asp.net - 这在wordpress上可以实现吗?
- java - Swing JLabel:提供文本和下划线之间的间隙
- javascript - 在内部数组中查找域值
- c# - 寻找通用日志接口以在 NuGet 包中创建通用日志记录
- node.js - nodejs函数的语法
- angular - 如何从 Observable 获取字符串值
?