5 minutes read

Ansible Collection

Install the phoenixNAP Ansible collection and use its playbooks to automate infrastructure management tasks.
Marko Aleksic
· Updated
November 27, 2026

Use the phoenixNAP Bare Metal Cloud (BMC) Ansible collection to automate server lifecycle management through YAML playbooks. This guide covers installing the collection, configuring API credentials, and using playbooks.

Prerequisites

Ansible and Python (with the requests package) installed on your system. You will also need a BMC account and API credentials with the bmc scope.

Step 1: Install the BMC Ansible Module

1. Install the phoenixNAP BMC module:

ansible-galaxy collection install phoenixnap.bmcCode language: Bash (bash)

2. View the module documentation:

ansible-doc phoenixnap.bmc.serverCode language: Bash (bash)

The Ansible BMC plugin depends on API requests.

Find out more

API overview

Step 2: Configure API Credentials

1. In your home directory, create a .pnap directory and a config.yaml file inside it:

mkdir -p ~/.pnap
nano ~/.pnap/config.yamlCode language: Bash (bash)

2. Add your BMC API credentials:

clientId: [YOUR_CLIENT_ID]
clientSecret: [YOUR_CLIENT_SECRET]Code language: YAML (yaml)

Replace the example values with your actual ID and secret.

3. Save the file.

Warning

Keep the credentials secure and do not commit the file to version control.

Step 3: Run Ansible Playbooks

Ansible playbooks are YAML files that describe the desired state of managed resources. The BMC collection compares the current server state with the state defined in the playbook and performs the required operations.

To run a playbook, use:

ansible-playbook [PLAYBOOK_NAME].ymlCode language: Bash (bash)

The examples below use localhost as the playbook host because the collection makes API requests from the control machine. They do not require Ansible agents on the BMC server.

Each example uses the phoenixnap.bmc collection and loads credentials from the configuration file. Replace hostnames and server IDs with values from your BMC account.

Create a Server

playbook_create.yml

- name: Create new servers for account
  hosts: localhost
  gather_facts: false
  vars_files:
    - ~/.pnap/config.yaml
  collections:
    - phoenixnap.bmc
  tasks:
  - server:
      client_id: "{{clientId}}"
      client_secret: "{{clientSecret}}"
      hostnames: [SERVER_NAME]
      location: PHX
      os: ubuntu/bionic
      type: s1.c1.medium
      state: present
      ssh_key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
Code language: YAML (yaml)

The playbook requests a server named [SERVER_NAME] in Phoenix. It specifies the operating system, server type, and SSH public key.

Deprovision a Server

Warning

Deprovisioning a server can cause service interruptions and data loss. Back up required data and verify the target server before running the playbook.

playbook_deprovision.yml

- name: reset servers
  hosts: localhost
  gather_facts: false
  vars_files:
    - ~/.pnap/config.yaml
  collections:
    - phoenixnap.bmc
  tasks:
  - server:
      client_id: "{{clientId}}"
      client_secret: "{{clientSecret}}"
      hostnames: [SERVER_NAME]
      state: absent
Code language: YAML (yaml)

Power Off a Server

playbook_power_off.yml

- name: power on servers
  hosts: localhost
  gather_facts: false
  vars_files:
    - ~/.pnap/config.yaml
  collections:
    - phoenixnap.bmc
  tasks:
  - server:
      client_id: "{{clientId}}"
      client_secret: "{{clientSecret}}"
      hostnames: [SERVER_HOSTNAME]
      state: powered-off
Code language: YAML (yaml)

Power On Server

playbook_power_on.yml

- name: power on servers
  hosts: localhost
  gather_facts: false
  vars_files:
    - ~/.pnap/config.yaml
  collections:
    - phoenixnap.bmc
  tasks:
  - server:
      client_id: "{{clientId}}"
      client_secret: "{{clientSecret}}"
      hostnames: [SERVER_HOSTNAME]
      state: powered-on
Code language: YAML (yaml)

Reboot Server

playbook_reboot.yml

- name: reset servers
  hosts: localhost
  gather_facts: false
  vars_files:
    - ~/.pnap/config.yaml
  collections:
    - phoenixnap.bmc
  tasks:
  - server:
      client_id: "{{clientId}}"
      client_secret: "{{clientSecret}}"
      hostnames: [SERVER_HOSTNAME]
      state: rebooted
Code language: YAML (yaml)

Reset Server

playbook_reset.yml

- name: reset servers
  hosts: localhost
  gather_facts: false
  vars_files:
    - ~/.pnap/config.yaml
  collections:
    - phoenixnap.bmc
  tasks:
  - server:
      client_id: "{{clientId}}"
      client_secret: "{{clientSecret}}"
      hostnames: [SERVER_HOSTNAME]
      ssh_key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
      state: reset
Code language: YAML (yaml)

Shutdown Server

This example uses server_ids instead of hostnames.

playbook_shutdown.yml

- name: shutdown servers
  hosts: localhost
  gather_facts: false
  vars_files:
    - ~/.pnap/config.yaml
  collections:
    - phoenixnap.bmc
  tasks:
  - server:
      client_id: "{{clientId}}"
      client_secret: "{{clientSecret}}"
      server_ids:
        - [ID]
      state: shutdownCode language: YAML (yaml)