模块get_url结果过滤器

时间:2019-06-20 13:09:48

标签: ansible

当我将URL列表作为参数传递时,我想解析get_url的特定输出。

我知道我可以得到{{ get_url_results1.results }}级别的输出

但是,我在解析低于“结果”级别的输出时遇到了麻烦。

预先感谢:-)

过滤器和正则表达式的各种组合

- name: "Verify: MY_FILE_LIST was passed as parameter"
  local_action: 
    module: shell
      echo "{{ lookup('env','MY_FILE_LIST') }}"
  register: echo_my_file_list
  failed_when: echo_my_file_list.stdout ==""
- debug:
    msg: "{{ echo_my_file_list.stdout.split('\n') }}"  

- name: "Get Release Files from Artifactory"
  local_action: 
    module: get_url 
    url: "{{ item }}" 
    dest: "{{ lookup('env','WORKSPACE') }}"
    force_basic_auth: yes 
    url_username: "{{ lookup('env','MY_USERID') }}"
    url_password: "{{ lookup('env','MY_PASSWORD') }}"
    validate_certs: no      
    mode: 0755
  with_items:
  - "{{ echo_my_file_list.stdout_lines }}"   
  register: get_url_results1
- name: "DEBUG: Get Release Files from Artifactory"
  debug:
    msg: "{{ get_url_results1 }}" 

对于要检索的每个文件,我只想从“模块:get_url”中输出以下内容。

"checksum_dest": "06f787da1b7b4c0bb0bb58bd90493165a96ea4ff",
"checksum_src": "06f787da1b7b4c0bb0bb58bd90493165a96ea4ff",

1 个答案:

答案 0 :(得分:0)

我发现这可行:

- name: "DEBUG: Get Release Files from Artifactory"
  debug:
    msg:
      - "Checksum of files from source:"
      - "{{ get_url_results.results | map(attribute='item') | list }}"
      - "{{ get_url_results.results | map(attribute='md5sum') | list }}"