Telegram
+998 (71) 205-80-00

Ansible for serverplus: infrastructure and server setup

Posted: 25.07.26
Share

Ansible for serverplus

Ansible on serverplus works at two levels. First, the openstack.cloud collection creates and deletes the infrastructure itself (servers, keys, networks) declaratively. Second, ordinary playbooks configure already-running servers over SSH. And a dynamic inventory pulls the list of servers straight from OpenStack — no need to maintain a host list by hand.

Installation

pip install "ansible>=9" openstacksdk
ansible-galaxy collection install openstack.cloud

ansible --version

Access comes from the same ~/.config/openstack/clouds.yaml as for the CLI/Terraform. The modules read it by cloud name (the OS_CLOUD variable).

Creating a server

The create.yml playbook runs locally and talks to the serverplus API:

- hosts: localhost
  gather_facts: false
  environment:
    OS_CLOUD: serverplus
  tasks:
    - name: SSH key
      openstack.cloud.keypair:
        name: ansible-key
        public_key_file: ~/.ssh/id_rsa.pub

    - name: Server
      openstack.cloud.server:
        name: web-1
        image: "Ubuntu 22.04"
        flavor: m1.small
        key_name: ansible-key
        network: private
        security_groups: [default]
        auto_ip: true
      register: srv

    - debug:
        var: srv.server.access_ipv4

About networking. As everywhere: the server's network must have a router with an external gateway, otherwise there is no internet.

Dynamic inventory

An inventory.openstack.yml file — Ansible pulls your servers from OpenStack automatically:

plugin: openstack.cloud.openstack
expand_hostvars: true
all_projects: false
export OS_CLOUD=serverplus
ansible-inventory -i inventory.openstack.yml --list
ansible -i inventory.openstack.yml all -m ping

Configuring servers over SSH

From here it is plain Ansible. An example site.yml: install and start nginx:

- hosts: all
  become: true
  tasks:
    - name: nginx
      apt:
        name: nginx
        state: present
        update_cache: true

    - name: start and enable
      service:
        name: nginx
        state: started
        enabled: true

Connection parameters are conveniently set in ansible.cfg:

[defaults]
remote_user = ubuntu
private_key_file = ~/.ssh/id_rsa
host_key_checking = False

Security

  • Keep clouds.yaml protected: chmod 600, out of git; use application credentials, not your account password.
  • Secrets go in ansible-vault (ansible-vault encrypt), not in plaintext.
  • Separate SSH keys for automation, rotated periodically.

FAQ

"openstacksdk is required" error. Install openstacksdk into the same Python environment where Ansible lives.

The inventory is empty. Check OS_CLOUD=serverplus and that servers actually exist (openstack server list).

SSH won't connect. You need a floating IP, an open port 22 and the right user/key (for Ubuntu — ubuntu).

Recommended
Find the best solution for your project
Fill in the data and you will be contacted by the manager for confirmation
Technical support number
+998 (71) 205-80-00
Email for communication
info@serverplus.uz
Working hours
How would you prefer to receive a consultation?
What are you interested in? (optional)
Free consultation
The engineer will answer, not the operator
No spam or intrusive sales
Do you want to try it yourself first?Each new user is awarded 100,000 UZS of bonuses for testing VPS, Dedicated Server, S3 storage and Kubernetes.
Register and receive a bonus
We do not transfer your data to third parties
Subscribe to our newsletter

Be one of the first to hear news from the hosting industry.