[tutorial Ansible 1.4] a variable with multiple values

Proxy configuration
===================

Add env_proxy.no_proxy for proxy exception

---
env_proxy:
  host: proxy.example.net
  no_proxy:
    - localhost
    - 192.168.1.1
    - .ac-dijon.fr

Examples of Ops inventory file
==============================

1/ INVALID, must be a list:

---
env_proxy:
  host: proxy.example.net
  no_proxy: localhost

2/ INVALID, an integer:

---
env_proxy:
  host: proxy.example.net
  no_proxy:
    - 1

3/ INVALID, without value:

---
env_proxy:
  host: proxy.example.net
This commit is contained in:
egarette@silique.fr 2023-12-18 11:34:32 +01:00
parent 069582559d
commit f1a276f3d5
4 changed files with 29 additions and 0 deletions

View file

@ -4,3 +4,6 @@
- name: Display variable env_proxy_all.port - name: Display variable env_proxy_all.port
ansible.builtin.debug: ansible.builtin.debug:
var: env_proxy_all.port var: env_proxy_all.port
- name: Display variable env_proxy_all.no_proxy
ansible.builtin.debug:
var: env_proxy_all.no_proxy

View file

@ -11,3 +11,17 @@
that: that:
- env_proxy.port is not defined or env_proxy.port is string or env_proxy.port is integer - env_proxy.port is not defined or env_proxy.port is string or env_proxy.port is integer
fail_msg: "La variable n'existe pas ou est de mauvais type !" fail_msg: "La variable n'existe pas ou est de mauvais type !"
- name: Test variable env_proxy.no_proxy
ansible.builtin.assert:
that:
- env_proxy.no_proxy is defined
- env_proxy.no_proxy | type_debug == 'list'
fail_msg: "La variable n'existe pas ou est de mauvais type !"
- name: Test variable env_proxy.no_proxy is a list of string
ansible.builtin.assert:
that:
- no_proxy is string
fail_msg: "La variable n'existe pas ou est de mauvais type !"
loop: "{{ env_proxy.no_proxy }}"
loop_control:
loop_var: no_proxy

View file

@ -2,3 +2,4 @@
env_proxy_all: env_proxy_all:
host: "{{ env_proxy.host }}" host: "{{ env_proxy.host }}"
port: "{{ env_proxy.port | default(3128) }}" port: "{{ env_proxy.port | default(3128) }}"
no_proxy: "{{ env_proxy.no_proxy }}"

11
doc.md
View file

@ -17,12 +17,18 @@ to make network connections to network services outside its own network.
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **host**<br/>`mandatory`<br/>**Type:** [`domainname`](https://forge.cloud.silique.fr/stove/rougail/src/branch/main/doc/variable/README.md#le-type-de-la-variable) | The proxy servers address.<br/>Specifies the hostname of proxy server to enable proxy server access to all of your HTTP(s) requests. .<br/>**Example:** proxy.silique.fr | | **host**<br/>`mandatory`<br/>**Type:** [`domainname`](https://forge.cloud.silique.fr/stove/rougail/src/branch/main/doc/variable/README.md#le-type-de-la-variable) | The proxy servers address.<br/>Specifies the hostname of proxy server to enable proxy server access to all of your HTTP(s) requests. .<br/>**Example:** proxy.silique.fr |
| **port**<br/>`mandatory`<br/>**Type:** [`port`](https://forge.cloud.silique.fr/stove/rougail/src/branch/main/doc/variable/README.md#le-type-de-la-variable) | The proxy server's port.<br/>**Default:** 3128 | | **port**<br/>`mandatory`<br/>**Type:** [`port`](https://forge.cloud.silique.fr/stove/rougail/src/branch/main/doc/variable/README.md#le-type-de-la-variable) | The proxy server's port.<br/>**Default:** 3128 |
| **no_proxy**<br/>`mandatory`, `multiple`<br/>**Type:** [`domainname`](https://forge.cloud.silique.fr/stove/rougail/src/branch/main/doc/variable/README.md#le-type-de-la-variable) | Exclude proxy server.<br/>Network address(es), network address range(s) and domains to exclude from using the proxy when initiating connection(s). .<br/>**Examples:** 192.168.1.1, 192.168.10.0/24, www.silique.fr, .internal.silique.fr |
# Example with mandatories variables # Example with mandatories variables
``` ```
env_proxy: env_proxy:
host: proxy.silique.fr host: proxy.silique.fr
no_proxy:
- 192.168.1.1
- 192.168.10.0/24
- www.silique.fr
- .internal.silique.fr
``` ```
# Example with all variables # Example with all variables
@ -31,4 +37,9 @@ env_proxy:
env_proxy: env_proxy:
host: proxy.silique.fr host: proxy.silique.fr
port: '3128' port: '3128'
no_proxy:
- 192.168.1.1
- 192.168.10.0/24
- www.silique.fr
- .internal.silique.fr
``` ```