ansible:将 wordpress 唯一键和盐的内容插入到变量中

ansible:将 wordpress 唯一键和盐的内容插入到变量中

在 handlers/main.yml 中我有:

- name: get API information for wp-config
       uri:
        url: "https://api.wordpress.org/secret-key/1.1/salt/"
        return_contents: yes
       register: api_info

我正在尝试运行的任务是:

- name: copy sample config file
  copy:
    src: /var/www/wordpress/wp-config-sample.php
    dest: /var/www/wordpress/wp-config.php
    remote_src: yes
  notify: get API information for wp-config

 - name: run API handler now
   meta: flush_handlers

 - name: insert unique key and salts in wp-config
   lineinfile:
     path: /var/www/wordpress/wp-config.php
     regex: "put your unique phrase here"
     insertafter: "put your unique phrase here"
     line: "{{ api_info }}"

不幸的是,变量 api_info 的值不是内容本身,而是:

{'status': 200, 'cookies': {}, 'date': 'Thu, 25 Oct 2018 14:53:42 GMT', 'url': 'https://api.wordpress.org/secret-key/1.1/salt/', 'transfer_encoding': 'chunked', 'changed': False, 'server': 'nginx', 'failed': False, 'connection': 'close', 'content_type': 'text/plain;charset=utf-8', 'msg': 'OK (unknown bytes)', 'redirected': False, 'x_frame_options': 'SAMEORIGIN', 'cookies_string': ''}

我如何才能获取该网站的实际内容?

提前致谢!

答案1

有一个小错误,参数不是return_contentreturn_contents模块uri将返回 uri 调用的内容api_info.content

---

- hosts: localhost

  tasks:

    - name: get API information for wp-config
      uri:
        url: "https://api.wordpress.org/secret-key/1.1/salt/"
        return_content: True
        method: GET
      register: api_info

    - debug:
        msg: "{{ api_info.content }}"

相关内容