brgalloway.phpipam_api

Playbooks for Using the phpipam API

Once you have phpipam installed, you can enable its API and use it in your Ansible playbooks. To do this, you’ll need to set up an app ID and create a user who will access the API to get a token.

Setting Up the API in Ansible

  1. Go to the API section in the phpipam web interface under Administration.
  2. Here, you can set your app ID for the API.
  3. Then, go to the Users section to create your API user.

Working with the API

To find subnet information and set specific variables, you'll want to explore the API using tools like Postman or curl.

Using curl to get a token:

curl -k https://ipam.example.com/api/phpipamappid/user/ -X POST -u <username>:<password>

Get the token from the returned JSON:

curl -k https://ipam.example.com/api/phpipamappid/sections/ --header "token: .J1e9ipFZkPE6EvIRAqEf9hp" -X GET

Once you have the section ID, you can find the subnets in that section:

curl -k https://ipam.example.com/api/phpipamappid/sections/{ID}/subnets --header "token: .J1e9ipFZkPE6EvIRAqEf9hp" -X GET

This will show all the subnets in the section. You’ll need the ID from the returned objects:

"data": {
    "id": <number>,
    ...
}

This is where you set the subnet_id: variable.

Example Playbook for Reserving an IP

The main.yml playbook shows how to use the URI module to make an API call. It registers the output to set variables, registers an IP, and updates the phpipam database.

To create the encrypted value needed for the api_pass variable in the vault, you’ll use ansible-vault. More details can be found here.

Make sure all values in the group_vars/all file match your environment for the playbook to work successfully. The API call will retrieve the token, which will be stored in a variable and used throughout the playbook.

For more information on the phpipam API, you can refer to the phpipam documentation.

Informazioni sul progetto

Get available ip from phpipam and reserve returned ip address

Installa
ansible-galaxy install brgalloway.phpipam_api
Licenza
gpl-2.0
Download
317
Proprietario