小编Mud*_*aer的帖子

Ansible随机UUID生成

在我的Ansible脚本中,我希望动态生成UUID并在以后使用它们.

这是我的方法:

- shell: echo uuidgen
  with_sequence: count=5
  register: uuid_list


  - uri: 
      url: http://www.myapi.com
      method: POST
      body: "{{ item.item.stdout }}"
    with_items: uuid_list.result
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

fatal: [localhost] => One or more undefined variables: 'str object' has no attribute 'stdout'
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

ansible

13
推荐指数
5
解决办法
2万
查看次数

通过Ansible将Json发布到API

我想通过Ansible向API端点发出POST请求,其中post数据中的一些项是动态的,这是我尝试失败的内容:

我的body_content.json:

{
  apiKey: '{{ KEY_FROM_VARS }}',
  data1: 'foo',
  data2: 'bar'
}
Run Code Online (Sandbox Code Playgroud)

这是我的Ansible任务:


# Create an item via API
- uri: url="http://www.myapi.com/create"
       method=POST return_content=yes HEADER_Content-Type="application/json"
       body="{{ lookup('file','create_body.json') | to_json }}"
Run Code Online (Sandbox Code Playgroud)

可悲的是,这不起作用:

failed: [localhost] => {"failed": true}
msg: this module requires key=value arguments
....
FATAL: all hosts have already failed -- aborting
Run Code Online (Sandbox Code Playgroud)

我的ansible版本是1.9.1

ansible ansible-playbook

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

ansible ×2

ansible-playbook ×1