trying to convert a dummy String with list but skipping the first iteration

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”,
myserver.nndc.kp.org”,
“{{ item | trim }}”
]

skipping the first iteration

Hii

i am trying to convert a dummy String with list but skipping the first iteration

“Dummy string” - unclear what that is

Convert string with list - unclear what that means

Convert string with list but skipping first iteration - unclear. Do you want to skip the first iteration? or does that happen but you do not want that?

There are so many items unclear that I can’t even start to help.
Please try to rephrase it to make it more clear.
Ideally you post the data structure that you have, and the structure you would like to have.

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

The Input Which i passed

client_nfs_export_server_string_ui: ‘172.11.12.13, 127.0.0.1 , 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
]
}

Let’s start with the low-hanging fruit. Mustaches don’t nest, so change this:

client_nfs_export_server_list: “{{ client_nfs_export_server_list | default() + [‘{{ server_list }}’] }}”

to this:

client_nfs_export_server_list: “{{ client_nfs_export_server_list | default() + [ server_list ] }}”

and see if that gets you to a better place.

% 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

Thanks Walter,

This one worked

client_nfs_export_server_list: “{{ client_nfs_export_server_string_ui.split(‘,’) | map(‘trim’) | list }}”