-
Notifications
You must be signed in to change notification settings - Fork 5
Usage Examples
DenAV edited this page Mar 15, 2026
·
4 revisions
- name: NPM - create proxy host
hosts: localhost
gather_facts: no
roles:
- role: npm-management
npm_api_domain_name: "site.example.com"
npm_api_host: "172.16.1.10"
npm_api_state: present- name: NPM - create proxy host with SSL
hosts: localhost
gather_facts: no
roles:
- role: npm-management
npm_api_domain_name: "secure.example.com"
npm_api_host: "172.16.1.20"
npm_api_ssl_forced: true
npm_api_state: presentUsing the module directly to specify a non-default forward port:
- name: Create proxy host on custom port
npm_proxy:
url: "{{ npm_api_url }}"
token: "{{ npm_access_token.json.token }}"
domain: "app.example.com"
host: "172.16.1.30"
host_port: 8080
ssl_forced: true
state: present
delegate_to: localhostUsing the module directly:
- name: Delete proxy host
npm_proxy:
url: "{{ npm_api_url }}"
token: "{{ npm_access_token.json.token }}"
domain: "old-site.example.com"
host: "172.16.1.10"
state: absent
delegate_to: localhostNote: Deleting a proxy host with a certificate will also delete the associated certificate.
Create multiple proxy hosts from a list:
# vars/proxy_hosts.yml
proxy_hosts:
- domain: "site-a.example.com"
host: "172.16.1.10"
ssl: true
- domain: "site-b.example.com"
host: "172.16.1.20"
ssl: false
- domain: "site-c.example.com"
host: "172.16.1.30"
host_port: 3000
ssl: true- name: Create multiple proxy hosts
npm_proxy:
url: "{{ npm_api_url }}"
token: "{{ npm_access_token.json.token }}"
domain: "{{ item.domain }}"
host: "{{ item.host }}"
host_port: "{{ item.host_port | default(80) }}"
ssl_forced: "{{ item.ssl | default(false) }}"
state: present
delegate_to: localhost
throttle: 1
loop: "{{ proxy_hosts }}"# Create encrypted credentials
ansible-vault create roles/npm-management/vars/api_secret.yml
# Run with vault password
ansible-playbook pl_npm-management.yml --ask-vault-pass
# Run with vault file
ansible-playbook pl_npm-management.yml --vault-password-file .vault-passThe role automatically:
- Validates credentials are defined (
asserttask) - Checks NPM API health (
urito API endpoint) - Obtains an access token (
POST /api/tokens) - Uses the token for proxy host operations
- Token is not persisted — obtained fresh each run
# On success (created)
msg: "Proxy-host site.example.com created"
changed: true
# On success (already exists)
msg: "Proxy Host site.example.com already exists"
changed: false
# On success (deleted)
msg: "Proxy-host: site.example.com removed."
changed: true
# On error
msg: "Failed to connect to api host to create for proxy_host. Info: ..."
failed: true