<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using Ansible uri module to add users to splunk via REST API in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343358#M63216</link>
    <description>&lt;P&gt;I had the same problem and this worked for me:&lt;/P&gt;

&lt;P&gt;- name: Create a hec token &lt;BR /&gt; uri:&lt;BR /&gt; url: &lt;A href="https://localhost:8089/servicesNS/nobody/your_app/data/inputs/http?output_mode=json" target="test_blank"&gt;https://localhost:8089/servicesNS/nobody/your_app/data/inputs/http?output_mode=json&lt;/A&gt;&lt;BR /&gt; user: admin&lt;BR /&gt; password: your_password&lt;BR /&gt; method: POST&lt;BR /&gt; body_format: form-urlencoded&lt;BR /&gt; body: &lt;BR /&gt; - [ name, token_name ]&lt;BR /&gt; - [ index, your_index ]&lt;BR /&gt; - [ sourcetype, your_sourcetype ]&lt;/P&gt;</description>
    <pubDate>Thu, 27 Feb 2020 09:26:14 GMT</pubDate>
    <dc:creator>noysherer</dc:creator>
    <dc:date>2020-02-27T09:26:14Z</dc:date>
    <item>
      <title>Using Ansible uri module to add users to splunk via REST API</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343351#M63209</link>
      <description>&lt;P&gt;So I want to elist Ansible to help me manage splunk users across 100's of Splunk servers around the world. I know how to add a splunk user via REST thats easy, but how could i load a user from a json structure with all the necessary elements in it, username, password, roles, emal etc... I believe that roles need to be a disctionary and not a string variable, am I incorrect on this? &lt;/P&gt;

&lt;P&gt;Any advice is much appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2018 22:38:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343351#M63209</guid>
      <dc:creator>brent_weaver</dc:creator>
      <dc:date>2018-04-19T22:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using Ansible uri module to add users to splunk via REST API</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343352#M63210</link>
      <description>&lt;P&gt;Trying to do the exact same thing right now, you are using the uri module?&lt;/P&gt;

&lt;P&gt;I can run API commands that doesn't take any input no problem, but I am having trouble passing the body...&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 20:25:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343352#M63210</guid>
      <dc:creator>farside41</dc:creator>
      <dc:date>2018-04-20T20:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using Ansible uri module to add users to splunk via REST API</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343353#M63211</link>
      <description>&lt;P&gt;My playbook is as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;---
    - hosts: splunk
      tasks:
        - uri:
            url: &lt;A href="https://localhost:8089/services/authentication/users" target="test_blank"&gt;https://localhost:8089/services/authentication/users&lt;/A&gt;
            follow_redirects: all
            method: POST
            return_content: yes
            timeout: 5
            status_code: 400,404,500,-1
            body_format: json
            body: "{{ lookup('file','user.json') }}"
            user: admin
            validate_certs: no
            password: NotMyPassword
          register: X

        - debug: msg="{{ X.status }}"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;With supporting users file being:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{ "user": "brent", "password": "nowayposted", "roles": [ "admin","user" ] }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I run it I get the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;local[~/git/splunk-build] $ ansible-playbook -i "splunk," -u root post.yml

PLAY [splunk] ***************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************************************************************************
ok: [splunk]

TASK [uri] ******************************************************************************************************************************************************************************************************************************************
ok: [splunk]

TASK [debug] ****************************************************************************************************************************************************************************************************************************************
ok: [splunk] =&amp;gt; {
    "msg": {
        "cache_control": "no-store, no-cache, must-revalidate, max-age=0",
        "changed": false,
        "connection": "Close",
        "content": "&amp;lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&amp;gt;\n&amp;lt;response&amp;gt;\n  &amp;lt;messages&amp;gt;\n    &amp;lt;msg type=\"ERROR\"&amp;gt;Cannot perform action \"POST\" without a target name to act on.&amp;lt;/msg&amp;gt;\n  &amp;lt;/messages&amp;gt;\n&amp;lt;/response&amp;gt;\n",
        "content_length": "179",
        "content_type": "text/xml; charset=UTF-8",
        "date": "Sat, 21 Apr 2018 00:02:22 GMT",
        "expires": "Thu, 26 Oct 1978 00:00:00 GMT",
        "failed": false,
        "msg": "HTTP Error 400: Bad Request",
        "redirected": false,
        "server": "Splunkd",
        "status": 400,
        "url": "https://localhost:8089/services/authentication/users",
        "vary": "Cookie, Authorization",
        "x_content_type_options": "nosniff",
        "x_frame_options": "SAMEORIGIN"
    }
}

PLAY RECAP ******************************************************************************************************************************************************************************************************************************************
splunk                     : ok=3    changed=0    unreachable=0    failed=0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I also approched it by going to the REST API directly and it does not seem to accept JSON as body input. So until I can get that to work I doubt Ansible will be able to do this.&lt;/P&gt;

&lt;P&gt;There is a whole other way to just use the command ansible module and call curl... Not for the purist though but it works like a charm. &lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 23:50:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343353#M63211</guid>
      <dc:creator>brent_weaver</dc:creator>
      <dc:date>2018-04-20T23:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: Using Ansible uri module to add users to splunk via REST API</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343354#M63212</link>
      <description>&lt;P&gt;You might need to send the body as a file. I did this for DBX using the following (bash function): &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;function create_input {
  for i in `seq 1 ${RETRY_MAX}`;
  do
    response=$(curl -k -u ${SPLUNK_USERNAME}:${SPLUNK_PASS} -H "Content-Type: application/json" -X POST -d @/config/${1} &lt;A href="https://${SPLUNK_HOST}/servicesNS/nobody/splunk_app_db_connect/db_connect/dbxproxy/inputs" target="test_blank"&gt;https://${SPLUNK_HOST}/servicesNS/nobody/splunk_app_db_connect/db_connect/dbxproxy/inputs&lt;/A&gt; | grep -o "There was an error")
    if [ "$response" != 'There was an error' ]; then
      echo "Database is up"
      break
    fi
    printf '.'
    sleep 2
    if [ "$i" -gt "$RETRY_MAX" ]; then
      echo "Database is not up"
      exit 1
    fi
  done
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So the argument to curl in ..."@/config/${1}"... is actually a json file that contains what I want to send as the body.&lt;/P&gt;

&lt;P&gt;Hope this helps,&lt;BR /&gt;
Tyler&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 22:42:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343354#M63212</guid>
      <dc:creator>tmuth_splunk</dc:creator>
      <dc:date>2018-04-23T22:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using Ansible uri module to add users to splunk via REST API</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343355#M63213</link>
      <description>&lt;P&gt;Tyler,&lt;/P&gt;

&lt;P&gt;Thank you for the response. I will do some testing and let you know. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 00:37:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343355#M63213</guid>
      <dc:creator>brent_weaver</dc:creator>
      <dc:date>2018-04-24T00:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using Ansible uri module to add users to splunk via REST API</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343356#M63214</link>
      <description>&lt;P&gt;So I must be missing something here:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;local[~/tmp/service_now] $ curl -k -u admin:password -H "Content-Type: application/json" -X POST -d @users.json &lt;A href="https://splunk:8089/services/authentication/users" target="test_blank"&gt;https://splunk:8089/services/authentication/users&lt;/A&gt; 
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;response&amp;gt;
  &amp;lt;messages&amp;gt;
    &amp;lt;msg type="ERROR"&amp;gt;Cannot perform action "POST" without a target name to act on.&amp;lt;/msg&amp;gt;
  &amp;lt;/messages&amp;gt;
&amp;lt;/response&amp;gt;
local[~/tmp/service_now] $ curl -k -u admin:jonesville -H "Content-Type: application/json" -X POST -d @users.json &lt;A href="https://splunk:8089/services/authentication/users" target="test_blank"&gt;https://splunk:8089/services/authentication/users&lt;/A&gt; 
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;response&amp;gt;
  &amp;lt;messages&amp;gt;
    &amp;lt;msg type="ERROR"&amp;gt;Cannot perform action "POST" without a target name to act on.&amp;lt;/msg&amp;gt;
  &amp;lt;/messages&amp;gt;
&amp;lt;/response&amp;gt;
local[~/tmp/service_now] $ cat users.json 
{ "name": "brent", "roles": ["admin"], "password": "cvftrsdsalle" }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is not working. &lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 14:22:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343356#M63214</guid>
      <dc:creator>brent_weaver</dc:creator>
      <dc:date>2018-04-25T14:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using Ansible uri module to add users to splunk via REST API</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343357#M63215</link>
      <description>&lt;P&gt;So I was trying to do this for automating the creation of an LDAP strategy and LDAP Groups. &lt;/P&gt;

&lt;P&gt;My solution to their Rest API not supporting json body was to put all the settings into a dict and then use this task to convery the JSON to a format the Rest API will understand:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;name: Build body variable for creating LDAP Strategy
set_fact:
ldap_strategy_body: "{{ldap_strategy_body|default('')}}{{ldap_setting.value.setting_name}}={{ldap_strategy.ldap_strategy_settings[ldap_setting.key]|default(ldap_setting.value.setting_value)}}&amp;amp;"
with_dict: "{{default_ldap_settings}}"
loop_control:
loop_var: ldap_setting
label: "Setting {{ldap_setting.key}}"&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:14:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343357#M63215</guid>
      <dc:creator>farside41</dc:creator>
      <dc:date>2020-09-29T19:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using Ansible uri module to add users to splunk via REST API</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343358#M63216</link>
      <description>&lt;P&gt;I had the same problem and this worked for me:&lt;/P&gt;

&lt;P&gt;- name: Create a hec token &lt;BR /&gt; uri:&lt;BR /&gt; url: &lt;A href="https://localhost:8089/servicesNS/nobody/your_app/data/inputs/http?output_mode=json" target="test_blank"&gt;https://localhost:8089/servicesNS/nobody/your_app/data/inputs/http?output_mode=json&lt;/A&gt;&lt;BR /&gt; user: admin&lt;BR /&gt; password: your_password&lt;BR /&gt; method: POST&lt;BR /&gt; body_format: form-urlencoded&lt;BR /&gt; body: &lt;BR /&gt; - [ name, token_name ]&lt;BR /&gt; - [ index, your_index ]&lt;BR /&gt; - [ sourcetype, your_sourcetype ]&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 09:26:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Using-Ansible-uri-module-to-add-users-to-splunk-via-REST-API/m-p/343358#M63216</guid>
      <dc:creator>noysherer</dc:creator>
      <dc:date>2020-02-27T09:26:14Z</dc:date>
    </item>
  </channel>
</rss>

