steampunk.unit.route (0.7.1) — module

Manage NGINX Unit route

Authors: Tadej Borovšak (@tadeboro)

Install collection

Install with ansible-galaxy collection install steampunk.unit:==0.7.1


Add to requirements.yml

  collections:
    - name: steampunk.unit
      version: 0.7.1

Description

Manage NGINX Unit route configuration.

Upstream docs are at U(https://unit.nginx.org/configuration/#routes).

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Route with a complex matching rule step and a static fallback step
  steampunk.unit.route:
    name: complex
    steps:
      - match:
          uri: /admin/*
          scheme: https
          arguments:
            mode: strict
            access: "!raw"
          cookies:
            user_role: admin
        action:
          pass: applications/cms
      - action:
          share: /www/static/
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

- name: Global routes for an imaginary blog site
  steampunk.unit.route:
    global: true
    steps:
      - match:
          host: blog.example.com/admin
          source: "*:8000-9000"
        action:
          pass: applications/blogs/admin
      - match:
          host:
            - blog.example.com
            - blog.*.org
          source: "*:8000-9000"
        action:
          pass: applications/blogs/core
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Static file serving with fallbacks
  steampunk.unit.route:
    name: static-site
    steps:
      - action:
          share: /www/static/
          fallback:
            share: /old/static/
            fallback:
              return 404

Inputs

    
name:
    description:
    - Name of the route to manage.
    - Required if I(global) is C(false). If I(global) is C(true), this parameter is ignored.
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - State of the manager resource.
    type: str

steps:
    description:
    - Route steps that are matched sequentially.
    - Required if I(state) is C(present).
    elements: dict
    suboptions:
      action:
        description:
        - Action to take if the step's matches.
        - See U(https://unit.nginx.org/configuration/#request-handling) for more details
          about all possible combinations of options.
        required: true
        suboptions:
          fallback:
            description:
            - A fallback route step that is taken if the file listed in the I(static)
              parameter is not found or cannot be accessed.
            - Format of this field is a nested route step. See nested routing example
              for more information about the format.
            type: dict
          location:
            description:
            - The location taht request should be redirected to.
            type: str
          pass:
            description:
            - Route's destination.
            type: str
          proxy:
            description:
            - Socket address of an HTTP server where the request is proxied.
            type: str
          return:
            description:
            - The HTTP response status code to be returned.
            - Use the I(location) paramter to specfy redirection target if status code
              implies one.
            type: int
          share:
            description:
            - A static path from where files are served upon a match.
            - Use I(fallback) option to specify what happens if the path is not accessible.
            type: str
        type: dict
      match:
        description:
        - Step's conditions to be matched.
        - See U(https://unit.nginx.org/configuration/#condition-matching) for more details
          about matching, case sensitivity of matches, etc.
        suboptions:
          arguments:
            description:
            - Parameter arguments supplied in the request URI.
            - See U(https://unit.nginx.org/configuration/#compound-matching) for more
              information about the format and semantics.
            elements: dict
            type: list
          cookies:
            description:
            - Cookies supplied with the request.
            - See U(https://unit.nginx.org/configuration/#compound-matching) for more
              information about the format and semantics.
            elements: dict
            type: list
          destination:
            description:
            - Target IP address and optional port of the request.
            - See U(https://unit.nginx.org/configuration/#simple-matching) for more information
              about the format and semantics.
            elements: str
            type: list
          headers:
            description:
            - Header fields supplied with the request.
            - See U(https://unit.nginx.org/configuration/#compound-matching) for more
              information about the format and semantics.
            elements: dict
            type: list
          host:
            description:
            - Host from the Host header field without port number, normalized by removing
              the trailing period (if any).
            - See U(https://unit.nginx.org/configuration/#simple-matching) for more information
              about the format and semantics.
            elements: str
            type: list
          method:
            description:
            - Method from the request line.
            - See U(https://unit.nginx.org/configuration/#simple-matching) for more information
              about the format and semantics.
            elements: str
            type: list
          scheme:
            choices:
            - http
            - https
            description:
            - URI scheme.
            - See U(https://unit.nginx.org/configuration/#simple-matching) for more information
              about the format and semantics.
            type: str
          source:
            description:
            - Source IP address and optional port of the request.
            - See U(https://unit.nginx.org/configuration/#simple-matching) for more information
              about the format and semantics.
            elements: str
            type: list
          uri:
            description:
            - URI path without arguments.
            - See U(https://unit.nginx.org/configuration/#simple-matching) for more information
              about the format and semantics.
            elements: str
            type: list
        type: dict
    type: list

global:
    default: false
    description:
    - Do not create or delete named routes and act on a global route.
    type: bool

provider:
    description:
    - Connection parameters.
    suboptions:
      ca_path:
        description:
        - Path to the CA bundle that should be used to validate the backend certificate.
        - If this parameter is not set, module will use the CA bundle that python is using.
        - Can also be set using the  I(UNIT_CA_PATH) environment variable.
        type: path
      endpoint:
        description:
        - HTTP or UNIX uri that should be used to communicate with the Unit.
        - The uri B(MUST) be prefixed by either C(http://), C(https://), or C(unix://).
        - By default, modules will try to connect to I(unix:///var/run/unit/control.sock),
          and if this socket does not exist, fallback to I(unix:///var/run/control.unit.sock).
        - Can also be set using the I(UNIT_ENDPOINT) environment variable.
        type: str
      password:
        description:
        - Password that is used when the I(endpoint) is protected using the basic authentication.
        - This parameter is ignored when the I(enpoint) parameter points to an unix socket.
        - Value is masked in the logs.
        - Can also be set using the I(UNIT_ENDPOINT) environment variable.
        type: str
      username:
        description:
        - Username that is used when the I(enpoint) is protected using the basic authentication.
        - This parameter is ignored when the I(enpoint) parameter points to an unix socket.
        - Can also be set using the I(UNIT_ENDPOINT) environment variable.
        type: str
      verify:
        default: true
        description:
        - Flag that controls the certificate validation.
        - If you are using self-signed certificates, you can set this parameter to C(false).
        - ONLY USE THIS PARAMETER IN DEVELOPMENT SCENARIOS! In you use self-signed certificates
          in production, see the I(auth.ca_path) parameter.
        - Can also be set using the  I(UNIT_VERIFY) environment variable.
        type: bool
    type: dict

Outputs

object:
  contains:
    name:
      description: Route name (can be C(None) for global routes).
      returned: always
      sample: my-route
      type: str
    steps:
      contains:
        action:
          contains:
            fallback:
              description: A fallback route step.
              returned: if specified
              type: dict
            location:
              description: The location taht request should be redirected to.
              returned: if specified
              type: str
            pass:
              description: Route's destination.
              returned: if specified
              type: str
            proxy:
              description: Socket address of an HTTP server where the request is proxied.
              returned: if specified
              type: str
            return:
              description: The HTTP response status code to be returned.
              returned: if specified
              type: int
            share:
              description: A static path from where files are served upon a match.
              returned: if specified
              type: str
          description: Action to take if the step's matches.
          returned: always
          type: dict
        match:
          contains:
            arguments:
              description: Parameter arguments supplied in the request URI.
              elements: dict
              returned: if specified
              type: list
            cookies:
              description: Cookies supplied with the request.
              elements: dict
              returned: if specified
              type: list
            destination:
              description: Target IP address and optional port of the request.
              elements: str
              returned: if specified
              type: list
            headers:
              description: Header fields supplied with the request.
              elements: dict
              returned: if specified
              type: list
            host:
              description: Host from the Host header field without port number.
              elements: str
              returned: if specified
              type: list
            method:
              description: Method from the request line.
              elements: str
              returned: if specified
              type: list
            scheme:
              description: URI scheme.
              returned: if specified
              type: str
            source:
              description: Source IP address and optional port of the request.
              elements: str
              returned: if specified
              type: list
            uri:
              description: URI path without arguments.
              elements: str
              returned: if specified
              type: list
          description: Step's conditions to be matched.
          returned: if specified
          type: dict
      description: List of steps in route
      elements: dict
      returned: always
      type: list
  description: Object representing NGINX Unit route.
  returned: On success and if I(state) == C(present)
  type: dict