thank you all for your findings and recommendations

In the same playbook I would like to explain one more scenario , I am using
set_facts to use above playbook output as input in the playbook, and I have
variables.yml

It has to go through loop and get the server details from each environment,
will my below playbook work
my variables.yml file
# Environment and os as input to pull all servers out of this
serverlist: "https://test-dev.test.com/testapi/test/server?environment={{
item }}&os=linux" +#
# item should be replaced with the item from the loop and pass it to below
playbook

vars_files:
    - "variables.yml"
  tasks:
    - name: set the facts per host
      set_fact:
        access_token: "{{ hostvars.localhost.output.stdout }}" # this is
the output of the above play
    - name: Make a post call to get server details
      shell: |
        cd /var/output/
        curl --location --request GET {{ serverlist }} \--header
Authorization: Bearer {{ access_token }} > /var/output/servers1.json
jq -r '.[]|.serverData[].servers[]' servers1.json >
/home/deploy-user/ansible/group_vars/servers1.yml
      register: data
    - debug: msg="data , {{ serverlist }}" # this need to replaced from one
var file
      loop:
        - dev
        - uat
        - stg2



On Fri, May 19, 2023 at 6:26 AM javed khan Siddque <
[email protected]> wrote:

> Thanks Walter,
>
>
> This one worked
> client_nfs_export_server_list: "{{ client_nfs_export_server_string_ui.
> split(',') | map('trim') | list }}"
>
> On Friday, May 19, 2023 at 5:13:49 PM UTC+5:30 Rowe, Walter P. (Fed) wrote:
>
>> % ansible -e 'input="172.11.12.13, 127.0.0.1 , test123.kp.org"' -m debug
>> -a msg="{{ input | split(',') | *map('trim')* | list }}" localhost -i
>> localhost,
>>
>>
>> localhost | SUCCESS => {
>>
>>     "msg": [
>>
>>         "172.11.12.13",
>>
>>         "127.0.0.1",
>>
>>         "test123.kp.org"
>>
>>     ]
>>
>> }
>>
>> Note the use of "map('trim')" this applying trim to each item in the list.
>>
>> Walter
>> --
>> Walter Rowe, Division Chief
>> Infrastructure Services, OISM
>> Mobile: 202.355.4123 <(202)%20355-4123>
>>
>> On May 18, 2023, at 2:48 PM, javed khan Siddque <[email protected]>
>> wrote:
>>
>> The Input Which i passed
>>
>>
>> *client_nfs_export_server_string_ui: '172.11.12.13, 127.0.0.1
>> , test123.kp.org <http://test123.kp.org/>'*
>>
>> there is some space before and after strings , which i require to trim
>> and create a fresh list.
>>
>>
>> expected output
>>
>> ok: [localhost] => {
>>     "msg": [
>>         "172.11.12.13",
>>         "127.0.0.1",
>>         "test123.kp.org",
>>         "myserver.nndc.kp.org"
>>     ]
>> }
>> On Friday, May 19, 2023 at 12:14:08 AM UTC+5:30 javed khan Siddque wrote:
>>
>>> Hi Dick,
>>>
>>> screenshots missed from my side.
>>> here we go.
>>>
>>>
>>> - name: "Converting String Input From - >
>>> client_nfs_export_server_string In A List After trim/split by comma ->
>>> client_nfs_export_server_list"
>>>   ansible.builtin.set_fact:
>>>     server_list: "{{ item | trim }}"
>>>     client_nfs_export_server_list: "{{ client_nfs_export_server_list |
>>> default([]) + ['{{ server_list }}'] }}"
>>>   loop: "{{ client_nfs_export_server_string_ui.split(',') }}"
>>>
>>>
>>> - name: "Print client_nfs_export_server_list Once"
>>>   ansible.builtin.debug:
>>>     msg: "{{ client_nfs_export_server_list }}"
>>>
>>>
>>>
>>>
>>> ok: [cnpdcstore117.ctolab.kp.org] => (item=172.11.12.13) => {
>>> 528
>>> "ansible_facts": {
>>> 529
>>> "client_nfs_export_server_list": [
>>> 530
>>> "{{ server_list }}"
>>> 531
>>> ],
>>> 532
>>> "server_list": "172.11.12.13"
>>> 533
>>> },
>>> 534
>>> "ansible_loop_var": "item",
>>> 535
>>> "changed": false,
>>> 536
>>> "item": "172.11.12.13"
>>> 537
>>> }
>>> 538
>>> ok: [cnpdcstore117.ctolab.kp.org] => (item= 127.0.0.1 ) => {
>>> 539
>>> "ansible_facts": {
>>> 540
>>> "client_nfs_export_server_list": [
>>> 541
>>> "172.11.12.13",
>>> 542
>>> "{{ server_list }}"
>>> 543
>>> ],
>>> 544
>>> "server_list": "127.0.0.1"
>>> 545
>>> },
>>> 546
>>> "ansible_loop_var": "item",
>>> 547
>>> "changed": false,
>>> 548
>>> "item": " 127.0.0.1 "
>>> 549
>>> }
>>> 550
>>> ok: [cnpdcstore117.ctolab.kp.org] => (item= test123.kp.org) => {
>>> 551
>>> "ansible_facts": {
>>> 552
>>> "client_nfs_export_server_list": [
>>> 553
>>> "172.11.12.13",
>>> 554
>>> "{{ server_list }}",
>>> 555
>>> "{{ server_list }}"
>>> 556
>>> ],
>>> 557
>>> "server_list": "test123.kp.org"
>>> 558
>>> },
>>> 559
>>> "ansible_loop_var": "item",
>>> 560
>>> "changed": false,
>>> 561
>>> "item": " test123.kp.org"
>>> 562
>>> }
>>> 563
>>>
>>>
>>>
>>>
>>> TASK [isilon_allocation_for_KPHC_environment : Print
>>> client_nfs_export_server_list Once] ***
>>> 00:01:11
>>> 565
>>> task path:
>>> /tmp/bwrap_1228189_9zrqk15v/awx_1228189_9shz6zke/project/roles/xxxxxxx/tasks/main.yml:25
>>> 566
>>> ok: [cnpdcstore117.ctolab.kp.org] => {
>>> 567
>>> "msg": [
>>> 568
>>> "172.11.12.13",
>>> 569
>>> "{{ server_list }}",
>>> 570
>>> "{{ server_list }}"
>>> 571
>>> ]
>>> 572
>>> }
>>> 573
>>> META: ending play
>>> 574
>>>
>>> On Thursday, May 18, 2023 at 11:41:46 PM UTC+5:30 javed khan Siddque
>>> wrote:
>>>
>>>> Hi Team,
>>>>
>>>> i am trying to convert a dummy String with list but skipping the first
>>>> iteration
>>>> i am getting below output
>>>>
>>>> *"client_nfs_export_server_list": *
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> *[             "127.0.0.1",             "test123.kp.org
>>>> <http://test123.kp.org/>",             "myserver.nndc.kp.org
>>>> <http://myserver.nndc.kp.org/>",             "{{ item | trim }}"   ]*
>>>>
>>>>
>>>>
>>>> skipping the first iteration
>>>>
>>>>
>>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/59e7a996-a262-48aa-8932-402755133c70n%40googlegroups.com
>> <https://groups.google.com/d/msgid/ansible-project/59e7a996-a262-48aa-8932-402755133c70n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/fc58ec13-6c63-40a9-9c1d-11d5a75120f6n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/fc58ec13-6c63-40a9-9c1d-11d5a75120f6n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
 Thanks,
Narmada Karthika Chitturi

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CABdF8S2rXe%3DMPmBhCodaJpoLbHGZ3ZgSTwifSxH8JcbhBEewSQ%40mail.gmail.com.

Reply via email to