Ansible TypeError:必须为字符串或缓冲区,而不是列表

时间:2019-09-03 18:47:15

标签: ansible ansible-2.x

下面的任务失败了,必须是字符串或缓冲区,而不是列表,并且当我在shell上使用相同的循环并且输出显示字符串时,因此不确定它出了错。我也用过loop,它也给出了相同的输出

- name: Provide Ambari cluster user role to users in file {{ cluster_user_group_file }}
  uri:
      url: "http://{{ ansible_fqdn }}:8080/api/v1/clusters/{{ cluster_name }}/privileges"
      method: POST
      force_basic_auth: yes
      user: "{{ ambari_admin_user }}"
      password: "{{ ambari_admin_password }}"
      headers: '{"X-Requested-By":"ambari"}'
      body: "[{\"PrivilegeInfo\":{\"permission_name\":\"CLUSTER.USER\",\"principal_name\":\"{{ item }}\",\"principal_type\":\"GROUP\"}}]"
      status_code: 200,201,202,409
      timeout: 60
      return_content: no
  with_items: "{{ lookup('file', '{{ cluster_user_group_file }}').split(',') }}"

1 个答案:

答案 0 :(得分:1)

这可以通过添加to_json并设置body_format: raw

来解决。
- name: Provide Ambari cluster user role to users in file {{ cluster_user_group_file }}
  uri:
      url: "http://{{ ansible_fqdn }}:8080/api/v1/clusters/{{ cluster_name }}/privileges"
      method: POST
      force_basic_auth: yes
      user: "{{ ambari_admin_user }}"
      password: "{{ ambari_admin_password }}"
      headers: '{"X-Requested-By":"ambari"}'
      body: "[{\"PrivilegeInfo\":{\"permission_name\":\"CLUSTER.USER\",\"principal_name\":\"{{ item }}\",\"principal_type\":\"GROUP\"}}]|to_json"
      body_format: raw
      status_code: 200,201,202,409
      timeout: 60
      return_content: no
  with_items: "{{ lookup('file', '{{ cluster_user_group_file }}').split(',') }}"
相关问题