Ansible is a configuration management tool used for provisioning, deploying, and orchestrating IT resources. Similarly to using Terraform, you can use Ansible to create and set up Gcore Cloud services.
You can find all Ansible modules and plugins required to interact with the Gcore Cloud in the Ansible Galaxy Collection for Gcore Cloud and in our official ansible-collection-gcore repository.
There are several methods for installing Ansible that depend on the type of your machine’s operating system.
If you already have Ansible installed, ensure that you’re using the recommended version of Python: 3.11 or higher. To check your Ansible and Python versions and get more details about the configuration, run ansible –version
.
Run the following command: apt-get install ansible
.
1. Install Extra Packages for Enterprise Linux (EPEL):
yum install epel-release
2. Install Python 3.11 or higher.
yum install python3.11
3. Install Ansible in your environment:
yum install ansible
You can also use pipx to install Ansible on most systems. For details, check out the official Ansible documentation.
We have a dedicated Ansible Galaxy Collection that contains all modules and plugins you need for interacting with the Gcore Cloud.
To install the collection, run the following command:
ansible-galaxy collection install gcore.cloud
You can now use all modules and plugins provided by the collection to manage your resources in the Gcore Cloud.
To ensure that everything works as expected, run a test playbook according to the following instructions.
1. Configure the playbook:
api_key
: The API key created in the Gcore Customer Portal in the profile settings. region_name
: A region in which your cloud resource is created. project_id
: An ID of the project that contains your cloud resources. You can check the ID in the Gcore Customer Portal on the Projects page.In the playbook configuration, add the ansible_python_interpreter: /usr/bin/python3.11
variable only if your Python version is lower than the recommended 3.11
.
2. Start the playbook: ansible-playbook ./get_instance.yaml -v
.
3. If you correctly configured Ansible, you should see one of the following:
Use modules and plugins from our Ansible Collection to create playbooks customized to your infrastructure requirements and deployment workflows.
As an example, let’s create a test.yaml
playbook that checks your quota limits creates a virtual instance if you have sufficient quotas.
To create and run the playbook:
1. Initialize a new “create_vm” role template.
ansible-galaxy init create_vm
2. Create a new task file in the tasks directory.
touch ./create_vm/tasks/check_quota.yaml
3. Configure the task to check if you have enough quotas to create the instance.
4. Create another task file touch ./create_vm/tasks/create_vm.yaml
.
5. Configure the task to create an instance.
6. Add all required tasks to the create_vm/tasks/main.yml
file:
7. Add any required variables to the create_vm/vars/main.yml
file. For example:
8. Create a playbook test.yaml
to test the “create_vm” role.
9. Run the playbook: ansible-playbook test.yaml
.
You should get one of the following outputs:
If everything is set up correctly, a new virtual instance will be created.
The information about your instance will appear in the ”Created VM Info” task section, and it’ll also be written to the log file.
If you don’t have sufficient quotas, you’ll get the “Needed quota” output, followed by the list of your current and requested quota limits. This information will also be stored in logs.
If you made a mistake in variables (for example, set a wrong flavor), you’ll get the “Failed” error. In this case, double-check the playbook configuration and rerun it.
Was this article helpful?
Discover our offerings, including virtual instances starting from 3.7 euro/mo, bare metal servers, AI Infrastructure, load balancers, Managed Kubernetes, Function as a Service, and Centralized Logging solutions.