Alter Ansible注册变量到位

Alter Ansible注册变量到位,ansible,Ansible,我正在编写一个Ansible角色,它将更新现有应用程序配置的设置。角色必须从应用程序的API获取设置。更改部分设置。然后POST将整个集合返回到应用程序 - name: Get Current Settings shell: curl -L -H "Accept: application/json" -u "{{auth}}" https://{{ server }}/api/settings register: settings - name: update settings

我正在编写一个Ansible角色,它将更新现有应用程序配置的设置。角色必须从应用程序的API获取设置。更改部分设置。然后
POST
将整个集合返回到应用程序

 - name: Get Current Settings
  shell: curl -L -H "Accept: application/json" -u "{{auth}}" https://{{ server }}/api/settings
  register: settings

 - name: update settings
   <Do something to modify settings.stdout as JSON>
   register: newSettings  # Save
   when: settings.Changed = True

 - name: Post Settings
   shell: curl -L -u "{{auth}}" -X POST -H "Content-Type: application/json" -d {{newSettings}}
-名称:获取当前设置
shell:curl-L-H“Accept:application/json”-u“{auth}}”https://{{server}}/api/settings
注册:设置
-名称:更新设置
注册:新闻设置#保存
时间:settings.Changed=True
-名称:发布设置
shell:curl-L-u“{{auth}”-X POST-H”内容类型:application/json“-d{newSettings}

<代码> > P> >我会考虑使用ANTIVE。< /P> 与HTTP和HTTPS web服务交互,并支持摘要、基本和WSSE HTTP身份验证机制

您可以使用
GET
完成第一部分:

- uri:
    url: http://www.example.com
    return_content: yes
  register: webpage
进行数据按摩,然后进行
POST

- name: Example POST
  uri:
    url: https://your.example.com/rest/api/2/issue/
    method: POST
    user: your_username
    password: your_pass
    body: "{{ lookup('file','issue.json') }}"
    force_basic_auth: yes
    status_code: 201
    body_format: json
编辑:

正如在注释中指出的,您可以使用这些注释设置从
GET
调用中收到的信息中更改的值

- set_fact: one_fact="something" other_fact="{{ local_var }}"

在put中,您可以访问新的事实,就像访问Ansible中的任何其他变量一样

我将查看URI模块。但是,这是我正在寻求帮助的信息处理。使用
set\u fact
根据
uri
的结果,使用数据处理的结果设置一个新变量,我最终使用了以下方法: