【问题标题】:Ansible Making variables optionalAnsible 使变量可选
【发布时间】:2021-05-05 12:48:36
【问题描述】:

我不会将参数省略与创建 vswitch 的任务一起使用。

我有错误'__omit_place_holder_81417e0c9c0a92falf5ce7dccf224fa67be93fb4'

我不明白这个问题

感谢您的帮助

- name: Add a VMware vSwitch with multiple NICs
  community.vmware.vmware_vswitch:
    hostname: "{{ hostname.1 }}"
    username: "{{ esxi_username }}"
    password: "{{ esxi_password }}"
    #esxi_hostname: "{{ hostname.1 }}"
    switch: "{{ item.name }}"
    nics: 
    - "{{ item.nic1| default(omit)}}"
    - "{{ item.nic2| default(omit)}}"
    mtu: "{{ item.mtu }}"
    number_of_ports: 2
    validate_certs: no
  delegate_to: localhost
  ignore_errors: yes
  loop:
    - "{{ net_vmk }}"
    - "{{ net_vm }}"
    - "{{ net_tech }}"
    - "{{ net_sto }}"
#conf esxi
hostname:
  1: lab-esxi
  2:
  3:
  4:
esxi_username: root
esxi_password: ...
#conf vswitch
net_vmk:
  name: vs-vmk
  nic2: vmnic4
  mtu: 1500

文档 Ansible [1]:https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#making-variables-optional

【问题讨论】:

    标签: python variables ansible yaml


    【解决方案1】:

    我找到了:-)

    - name: Add a VMware vSwitch with multiple NICs
      community.vmware.vmware_vswitch:
        hostname: "{{ hostname.1 }}"
        username: "{{ esxi_username }}"
        password: "{{ esxi_password }}"
        #esxi_hostname: "{{ hostname.1 }}"
        switch: "{{ item.name }}"
        nics: "{{ item.nic1|default(omit)}}"
        nics: "{{ item.nic2|default(omit)}}"
        mtu: "{{ item.mtu }}"
        number_of_ports: 2
        validate_certs: no
      delegate_to: localhost
      ignore_errors: yes
      loop:
        - "{{ net_vmk }}"
        - "{{ net_vm }}"
        - "{{ net_tech }}"
        - "{{ net_sto }}"
    

    【讨论】:

      猜你喜欢
      • 2022-01-23
      • 2022-07-19
      • 2022-01-23
      • 2015-12-18
      • 2017-08-30
      • 1970-01-01
      • 2020-12-02
      • 2021-12-01
      • 1970-01-01
      相关资源
      最近更新 更多