{"id":337,"date":"2025-04-15T08:25:44","date_gmt":"2025-04-15T08:25:44","guid":{"rendered":"https:\/\/blog.hostinger.io\/support\/2025\/04\/15\/11086323-using-hostinger-ansible-collection\/"},"modified":"2025-04-15T08:25:44","modified_gmt":"2025-04-15T08:25:44","slug":"11086323-using-hostinger-ansible-collection","status":"publish","type":"post","link":"https:\/\/www.hostinger.com\/support\/11086323-using-hostinger-ansible-collection\/","title":{"rendered":"Using Hostinger Ansible Collection"},"content":{"rendered":"<p class=\"no-margin\">The Hostinger Ansible collection is a powerful tool for automating the management of your Hostinger Virtual Private Servers (VPS) using Ansible. This article explains the collection and how to install it, as well as provides examples of how to use it in your automation workflows.<\/p><p class=\"no-margin\">\n<\/p><h2 id=\"h_ac7c1db3e9\">What is the Hostinger Ansible collection?<\/h2><p class=\"no-margin\">The Hostinger Ansible collection is a set of Ansible modules that interact with Hostinger&rsquo;s public API. These modules enable you to manage all aspects of your Hostinger VPS infrastructure through Ansible playbooks, including:<\/p><ul>\n<li>\n<p class=\"no-margin\">Managing firewalls and firewall rules<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Controlling VPS power state (start, stop, restart)<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Setting hostnames and SSH keys<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Creating and managing snapshots<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Installing malware protection<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Retrieving performance metrics<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Automating server provisioning<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Creating and managing post-install scripts<\/p>\n<\/li>\n<\/ul><p class=\"no-margin\">By using this collection, you can implement Infrastructure as Code (IaC) practices with your Hostinger VPS resources, making your server management more efficient, consistent, and repeatable.<\/p><p class=\"no-margin\">\n<\/p><h2 id=\"h_031257f2a1\">Installation<\/h2><p class=\"no-margin\">You can install the Hostinger Ansible collection using Ansible Galaxy, the official repository for <a href=\"https:\/\/galaxy.ansible.com\/ui\/repo\/published\/hostinger\/vps\/\" target=\"_blank\" class=\"intercom-content-link\" rel=\"noopener\">Ansible collections<\/a>.<\/p><p class=\"no-margin\">\n<\/p><h3 id=\"h_158fa667eb\">Installing from Ansible Galaxy<\/h3><pre><code>ansible-galaxy collection install hostinger.vps<\/code><\/pre><h3 id=\"h_f1749a5d8d\">Installing locally for development<\/h3><p class=\"no-margin\">If you want to contribute to the collection or need to install it from a local build:<\/p><pre><code>ansible-galaxy collection build<br>ansible-galaxy collection install hostinger-vps-*.tar.gz<\/code><\/pre><h2 id=\"h_97a3790913\">Available modules<\/h2><p class=\"no-margin\">The Hostinger Ansible collection includes a comprehensive set of modules that cover all aspects of VPS management, from firewall configuration and power management to post-install scripts and snapshots.<\/p><p class=\"no-margin\">Some of the key modules include:<\/p><ul>\n<li>\n<p class=\"no-margin\">VPS provisioning and power management<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Firewall management and rules<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Hostname and SSH key configuration<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Post-install script management<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Snapshot creation and restoration<\/p>\n<\/li>\n<\/ul><p class=\"no-margin\">Additionally, the collection provides a dynamic inventory plugin that automatically discovers your Hostinger VPS instances.<\/p><p class=\"no-margin\">For the complete list of available modules and detailed documentation, please visit the <a href=\"https:\/\/github.com\/hostinger\/ansible-collection-hostinger\" target=\"_blank\" class=\"intercom-content-link\" rel=\"noopener\">Hostinger Ansible collection GitHub repository<\/a>.<\/p><p class=\"no-margin\">\n<\/p><h2 id=\"h_97032e0cb2\">Configuration<\/h2><p class=\"no-margin\">To use the Hostinger Ansible collection, you must configure your Ansible environment with your Hostinger API credentials.<\/p><p class=\"no-margin\">\n<\/p><h3 id=\"h_8e8d895f91\">API Authentication<\/h3><p class=\"no-margin\">Create a configuration file in your Ansible project (e.g., <code>hostinger_api.yaml<\/code>):<\/p><pre><code>yaml--- hostinger_api_token: \"your_api_token_here\"<\/code><\/pre><p class=\"no-margin\">You can then reference this file in your playbooks or include it using the <code>vars_files<\/code> directive.<\/p><p class=\"no-margin\">\n<\/p><h2 id=\"h_d679a226b4\">Usage Examples<\/h2><p class=\"no-margin\">Here are some practical examples of how to use the Hostinger Ansible collection in your playbooks.<\/p><p class=\"no-margin\">\n<\/p><h3 id=\"h_f5713ed875\">Retrieving VPS Information<\/h3><pre><code>---<br>- name: Get VPS Information<br>  hosts: localhost<br>  vars_files:<br>    - hostinger_api.yaml<br>  tasks:<br>    - name: Get VPS details<br>      hostinger.vps.hostinger_vps_get_info:<br>        token: \"#{{ hostinger_api_token }}\"<br>        vps_id: 123456<br>      register: vps_info<br>    <br>    - name: Display VPS information<br>      debug:<br>        var: vps_info<\/code><\/pre><h2 id=\"h_a2cfd9c9b9\">Restart VPS<\/h2><pre><code>---<br>- name: Restart VPS<br>  hosts: localhost<br>  vars_files:<br>    - hostinger_api.yaml<br>  tasks:<br>    - name: Restart VPS<br>      hostinger.vps.hostinger_vps_power:<br>        token: \"#{{ hostinger_api_token }}\"<br>        vps_id: 123456<br>        state: restarted<br>      register: restart_result<br>    <br>    - name: Display restart result<br>      debug:<br>        var: restart_result<\/code><\/pre><h2 id=\"h_4c839853cb\">Creating and using post-install scripts<\/h2><pre><code>---<br>- name: Manage Post-Install Scripts<br>  hosts: localhost<br>  vars_files:<br>    - hostinger_api.yaml<br>  tasks:<br>    - name: Create LAMP stack post-install script<br>      hostinger.vps.hostinger_vps_postinstall_create:<br>        token: \"#{{ hostinger_api_token }}\"<br>        name: \"Install Docker\"<br>        content: |<br>          #!\/bin\/bash<br>          <br>          apt update &amp;&amp; apt install -y docker.io<br>      register: post_install_script<br>    <br>    - name: Reinstall VPS with post-install script<br>      hostinger.vps.hostinger_vps_reinstall:<br>        token: \"#{{ hostinger_api_token }}\"<br>        vps_id: 123456<br>        template_id: 4  # Ubuntu 22.04<br>        post_install_script_id: \"#{{ post_install_script.id }}\"<\/code><\/pre><p class=\"no-margin\">\n<\/p><h2 id=\"h_d6bca36244\">Troubleshooting<\/h2><h3 id=\"h_eccec5bcbb\">Common Issues<\/h3><ol>\n<li>\n<p class=\"no-margin\"><b>Authentication Errors<\/b>: Ensure your API token is correct and has the necessary permissions.<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\"><b>Module Not Found<\/b>: Ensure you have installed the collection correctly. Try reinstalling with <code>ansible-galaxy collection install hostinger.vps --force<\/code>.<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\"><b>API Rate Limiting<\/b>: If you make many API calls in a short period, you might hit rate limits. If needed, add delays between tasks.<\/p>\n<\/li>\n<li>\n<p class=\"no-margin\"><b>Error Messages<\/b>: Always check the returned error messages, which often provide specific details about what went wrong.<\/p>\n<\/li>\n<\/ol><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">The Hostinger Ansible collection provides a powerful way to automate your Hostinger VPS management tasks using Ansible. By incorporating these modules into your automation workflows, you can save time, reduce errors, and implement infrastructure as code practices for your Hostinger VPS resources.<\/p><p class=\"no-margin\">If you would like more information about Ansible collections and how to use them, please refer to the <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/user_guide\/collections_using.html\" target=\"_blank\" class=\"intercom-content-link\" rel=\"noopener\">official Ansible documentation<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introducing the Hostinger Ansible Collection<\/p>\n","protected":false},"author":581,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"include_on_kodee":true,"footnotes":""},"categories":[295],"tags":[],"class_list":["post-337","post","type-post","status-publish","format-standard","hentry","category-api"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/support\/11086323-using-hostinger-ansible-collection\/","default":1}],"include_on_kodee":true,"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/comments?post=337"}],"version-history":[{"count":0,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/337\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/media?parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/categories?post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/tags?post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}