-
Notifications
You must be signed in to change notification settings - Fork 5
Usage Examples
- 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 using the role variable npm_api_hosts:
# group_vars/npm.yml or --extra-vars
npm_api_hosts:
- domain_name: "site-a.example.com"
host: "172.16.1.10"
ssl_forced: false
- domain_name: "site-b.example.com"
host: "172.16.1.20"
ssl_forced: true
letsencrypt_email: "admin@example.com"
- domain_name: "site-c.example.com"
host: "172.16.1.30"
host_port: 3000
ssl_forced: true
letsencrypt_email: "admin@example.com"- name: NPM - batch create proxy hosts
hosts: localhost
gather_facts: no
roles:
- role: npm-managementThe role automatically splits the list into two phases:
-
Without SSL — hosts where
ssl_forcedisfalse(or inheritsnpm_api_ssl_forced: falsedefault). These run in parallel with no throttle, since no certificate provisioning is needed (timeout: 30s). -
With SSL — hosts where
ssl_forcedistrue. These run sequentially (throttle: 1) because each host triggers a Let's Encrypt certificate request via certbot, which can take 10-30 seconds. Running them in parallel would cause timeouts or rate-limit errors (timeout: 120s).
You do not need to separate the list manually — the role handles the split automatically based on each item's ssl_forced value (or the global npm_api_ssl_forced default).
Tip: If all your hosts need SSL, set the global default and omit
ssl_forcedper item:npm_api_ssl_forced: true npm_api_letsencrypt_email: "admin@example.com" npm_api_hosts: - domain_name: "site-a.example.com" host: "172.16.1.10" - domain_name: "site-b.example.com" host: "172.16.1.20"All hosts will be processed sequentially with SSL.
# 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