【问题标题】:Setting up correctly gateway_ip in Ansible function在 Ansible 函数中正确设置 gateway_ip
【发布时间】:2018-08-17 07:09:04
【问题描述】:

我正在使用以下函数使用 Ansible 和变量文件部署 Openstack 子网:

- name: Create the subnets 
  os_subnet: 
     cloud: "{{ item.cloud }}" 
     state: present
     validate_certs: no
     gateway_ip: "{{ item.gateway_ip | default(None) }}"
     dns_nameservers: "{{ item.dns if item.dns is defined else omit }}"
     enable_dhcp: yes
     name: "{{ item.subnet }}"
     network_name: "{{ item.network }}"
     cidr: "{{ item.cidr }}"
     allocation_pool_start: "{{ item.allocation_pool_start }}"
     allocation_pool_end: "{{ item.allocation_pool_end }}"
     host_routes: "{{ item.host_routes | default(omit) }}" 
  with_items: 
  - "{{ subnets }}"
  tags: subnets

在我的环境中,我将有一些配置了网关的子网,有些则没有。我想创建一个解决方法,以便可以为某些服务器配置网关 ip,而为其中一些服务器配置网关 ip 成为可能。

我还没有尝试过像这样配置它,但它也会为那些没有在变量文件中配置 gateway_ip 的网关分配一个网关。我也尝试过 no_gateway_ip 选项,但是对于这个选项,当它在变量文件中定义时,我没有找到合适的过滤器来获取 gateway_ip。

有什么办法可以骗过这个吗?

【问题讨论】:

    标签: ansible jinja2 openstack


    【解决方案1】:

    找到方法:应该涉及 no_gateway_ip,而不是 gateway_ip。

    - name: Create the subnets 
      os_subnet: 
         cloud: "{{ item.cloud }}" 
         state: present
         validate_certs: no
         no_gateway_ip: "{{ not (item.gateway_ip is defined) }}"
         dns_nameservers: "{{ item.dns if item.dns is defined else omit }}"
         enable_dhcp: yes
         name: "{{ item.subnet }}"
         network_name: "{{ item.network }}"
         cidr: "{{ item.cidr }}"
         allocation_pool_start: "{{ item.allocation_pool_start }}"
         allocation_pool_end: "{{ item.allocation_pool_end }}"
         host_routes: "{{ item.host_routes | default(omit) }}" 
      with_items: 
      - "{{ subnets }}"
      tags: subnets
    

    【讨论】:

      猜你喜欢
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多