I have a play where i need to use a loop to iterate through items
in it but the problem is the list items are having ,
in a string values such as ENT0005, bay 11
and ENT0005, bay 11
which i'm not able to get rid of.
My play:
- name: Create server profile
oneview_server_profile:
config: "{{ config }}"
data:
serverProfileTemplateName: "{{ server_profile_template }}"
serverHardwareName: "{{ item }}"
loop:
- "ENT0005, bay 11"
- "ENT0005, bay 12"
name: "{{ server_profile }}"
My trial:
This does not work as well..
serverHardwareName: "{{ item }}"
loop:
- "(ENT0005, bay 11)"
- "(ENT0005, bay 12)"
Please suggest.
EDIT:
---
- hosts: localhost
gather_facts: no
vars:
config: "{{ playbook_dir }}/{{ config_file }}"
contents: "{{lookup('file', config)}}"
server_profile_template: 'Test_apc_SY 480 Gen10 2 NVMe Application Template 20190601 V1.0'
server_hardware: "SY 480 Gen9 1"
#server_hardware_name: "ENT0005, bay 11" "ENT0005, bay 12"
server_profile: "apc_SY 480 Gen10 2 NVMe Application Template 20190601 V1.0"
template_name: []
server_list: []
tasks:
## Apply the server profile templates
- name: Create server profile
oneview_server_profile:
config: "{{ config }}"
data:
serverProfileTemplateName: "{{ server_profile_template }}"
serverHardwareName: "{{ item }}"
loop:
- "ENT0005, bay 11"
- "ENT0005, bay 12"
name: "{{ server_profile }}"
params:
force: True
delegate_to: localhost
register: result
- debug: msg= "{{ result.msg }}"
- debug: msg= "{{ result }}"
...
ERROR
fatal: [localhost]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined
The error appears to be in 'serverProfile.yml': line 19, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Create server profile
^ here
"
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…