Loop is not working with data type test as conditional in Ansible
Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram: https://www.instagram.com/ky.emrah
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Loop is not working with data type test as conditional in Ansible
When I execute ansible playbook with this command and extra vars as
ansible-playbook controller_config/windows_domain_names.yml -e "target_win_host=testserver.testdomain.com"
ansible-playbook controller_config/windows_domain_names.yml -e "target_win_host=testserver.testdomain.com"
with one task inside it
- name: Find if the variable target_win_host is a list
debug:
msg: "{{ item }} is list data type"
loop: "{{ target_win_host}}"
when: target_win_host | type_debug == 'list'
- name: Find if the variable target_win_host is a list
debug:
msg: "{{ item }} is list data type"
loop: "{{ target_win_host}}"
when: target_win_host | type_debug == 'list'
I got the error as
"Invalid data passed to 'loop', it requires a list, got this instead: testserver.testdomain.com. Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup."
"Invalid data passed to 'loop', it requires a list, got this instead: testserver.testdomain.com. Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup."
I expect the above block should be skipped as this does not meet the condition that variable is a list and that its a scalar (string).
I expect the above block should be skipped as this does not meet the condition that variable is a list and that its a scalar (string).
I tried with different condition as below
- name: Find if the variable target_win_host is a list
debug:
msg: "{{ item }} is list data type"
loop: "{{ target_win_host}}"
when: target_win_host is not string and target_win_host is iterable and target_win_host is sequence
- name: Find if the variable target_win_host is a list
debug:
msg: "{{ item }} is list data type"
loop: "{{ target_win_host}}"
when: target_win_host is not string and target_win_host is iterable and target_win_host is sequence
but same error as above.
Tags: ansibleSource of the question:
https://stackoverflow.com/questions/79002263
Question and source license information:
https://meta.stackexchange.com/help/licensing
https://stackoverflow.com/
Видео Loop is not working with data type test as conditional in Ansible канала Emrah KAYA
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Loop is not working with data type test as conditional in Ansible
When I execute ansible playbook with this command and extra vars as
ansible-playbook controller_config/windows_domain_names.yml -e "target_win_host=testserver.testdomain.com"
ansible-playbook controller_config/windows_domain_names.yml -e "target_win_host=testserver.testdomain.com"
with one task inside it
- name: Find if the variable target_win_host is a list
debug:
msg: "{{ item }} is list data type"
loop: "{{ target_win_host}}"
when: target_win_host | type_debug == 'list'
- name: Find if the variable target_win_host is a list
debug:
msg: "{{ item }} is list data type"
loop: "{{ target_win_host}}"
when: target_win_host | type_debug == 'list'
I got the error as
"Invalid data passed to 'loop', it requires a list, got this instead: testserver.testdomain.com. Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup."
"Invalid data passed to 'loop', it requires a list, got this instead: testserver.testdomain.com. Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup."
I expect the above block should be skipped as this does not meet the condition that variable is a list and that its a scalar (string).
I expect the above block should be skipped as this does not meet the condition that variable is a list and that its a scalar (string).
I tried with different condition as below
- name: Find if the variable target_win_host is a list
debug:
msg: "{{ item }} is list data type"
loop: "{{ target_win_host}}"
when: target_win_host is not string and target_win_host is iterable and target_win_host is sequence
- name: Find if the variable target_win_host is a list
debug:
msg: "{{ item }} is list data type"
loop: "{{ target_win_host}}"
when: target_win_host is not string and target_win_host is iterable and target_win_host is sequence
but same error as above.
Tags: ansibleSource of the question:
https://stackoverflow.com/questions/79002263
Question and source license information:
https://meta.stackexchange.com/help/licensing
https://stackoverflow.com/
Видео Loop is not working with data type test as conditional in Ansible канала Emrah KAYA
Комментарии отсутствуют
Информация о видео
1 декабря 2024 г. 17:30:19
00:01:30
Другие видео канала