venkata
venkata

Reputation: 477

Ansible TypeError: must be string or buffer, not list

Below task is failing with must be string or buffer, not list and when I use the same loop over shell and the output prints string, so not sure where it is going wrong. I have used loop also, it is also giving same output

- 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(',') }}"

Upvotes: 0

Views: 1378

Answers (1)

venkata
venkata

Reputation: 477

This is resolved by adding to_json and setting 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(',') }}"

Upvotes: 3

Related Questions