An Ansible playbook is a YAML-based configuration management and automation tool that defines tasks to be executed on remote systems. Playbooks are simple yet powerful, enabling users to automate tasks like software deployment, configuration management, and orchestration. Each playbook contains a series of "plays" that specify target hosts, tasks to perform, and any required variables or conditions. Playbooks are highly readable, making them ideal for managing complex IT environments by automating multiple systems simultaneously in a structured, repeatable way.
Since the interaction with Virtuozzo Application platform (VAP) is performed via the platform API, the built-in ansible.builtin.uri module can be used.
For example, to create a simple environment using createenvironment API method, build your first playbook on a server where Ansible is installed, e.g. playbook-create-env.yaml:
vim playbook-create-env.yaml
Insert the next code:
- name: VAP-PLAYBOOK
hosts: localhost
tasks:
- name: GET-SESSION
ansible.builtin.uri:
url: "https://$API_HOST/1.0/users/authentication/rest/signin"
method: POST
body_format: form-urlencoded
headers:
Content-Type: "application/x-www-form-urlencoded"
body:
login: "your_login"
password: "your_password"
appid: "cluster"
validate_certs: no
register: login_response
- name: CREATE-ENVIRONMENT
ansible.builtin.uri:
url: "https://$API_HOST/1.0/environment/control/rest/createenvironment"
method: POST
body_format: form-urlencoded
headers:
Content-Type: "application/x-www-form-urlencoded"
body:
nodes: '[{"count":1,"diskLimit":100,"extip":0,"extipv6":0,"fixedCloudlets":1,"flexibleCloudlets":4,"nodeGroup":"cp","nodeType":"apache","restartDelay":30,"scalingMode":"STATEFUL","tag":"2.4.62-php-8.3.10-almalinux-9"}]'
session: "{{ login_response.json.session }}"
actionkey: 'staging'
env: '{"ishaenabled":false,"region":"vz7","shortdomain":"first-environment","sslstate":false}'
ownerUid: '106'
timeout: 600
validate_certs: no
register: result
- name: SHOW-RESPONSE
debug:
var: result
where $API_HOST - URL of your hosting provider (Hoster’s URL / API column in the document).
Parameters in the createenv API method are given as an example. Feel free to adjust them to your needs.
Run the playbook from the server where Ansible is installed, using the created yaml file:
ansible-playbook playbook-create-env.yaml
Wait until the code is fully executed:
Confirm whether the environment was successfully created: