Ansible Tower 服务器声称它收到了一个错误的请求

Ansible Tower server claims it was sent a bad request

我已经编写了一个剧本来创建带有自定义凭据的凭据,下面是 ansible 剧本

---
- name: Trigger an Atower API
  hosts: localhost
  connection: local
  tasks:
    - name: Create a valid SCM credential from a private_key file
      command: tower-cli credential create --organization "Default" --name "DevOps User" --credential-type "csa-test2" --inputs "{'user':'devops', 'stg01_ssh_key':\"$( sed -z 's/\n/\n/g' test.pem )\" }"
      no_log: false

我收到与引号相关的错误

name", "DevOps User", "--credential-type", "csa-test2", "--inputs", "{'user':'devops', 'stg01_ssh_key':\"$( sed -z 's/\n/\n/g' test.pem )\" }"], "delta": "0:00:01.319114", "end": "2021-01-07 16:00:22.763388", "msg": "non-zero return code", "rc": 40, "start": "2021-01-07 16:00:21.444274", "stderr": "Error: The Tower server claims it was sent a bad request.\n\nPOST http://x.x.x.x:13080/api/v2/credentials/\nParams: None\nData: {\"inputs\": {\"stg01_ssh_key\": \"$( sed -z 's/\n/\n/g' test.pem )\", \"user\": \"devops\"}, \"credential_type\": 36, \"organization\": 1, \"name\": \"DevOps User\"}\n\nResponse: {\"inputs\":{\"stg01_ssh_key\":[\"Invalid certificate or key: $( sed -z 's/\n/\n/g' test.pem )...\"]}}", "stderr_lines": ["Error: The Tower server claims it was sent a bad request.", "", "POST http://x.x.x.x:13080/api/v2/credentials/", "Params: None", "Data: {\"inputs\": {\"stg01_ssh_key\": \"$( sed -z 's/\n/\n/g' test.pem )\", \"user\": \"devops\"}, \"credential_type\": 36, \"organization\": 1, \"name\": \"DevOps User\"}", "", "Response: {\"inputs\":{\"stg01_ssh_key\":[\"Invalid certificate or key: $( sed -z 's/\n/\n/g' test.pem )...\"]}}"], "stdout": "", "stdout_lines": []}

此外,当我手动尝试“tower-cli create”命令时,它工作正常。谁能帮我解决这个问题。我不知道这里有什么问题。

尝试使用 shell 而不是命令,文档说

命令将不会通过 shell 处理,因此像 $HOSTNAME 这样的变量和像 "*", "<", ">", "|", ";""&" 这样的操作将不起作用。如果您需要这些功能,请使用 ansible.builtin.shell 模块。

来源:Ansible Documentation