在我的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向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