Hostinger Ansible collection是一组与Hostinger公共API交互的Ansible模块,这些模块使用户能够通过Ansible playbook管理由美国主机商Hostinger提供的VPS主机基础设施的各个方面,如设置主机名和SSH密钥、管理防火墙、创建和管理快照等。为了帮助大家能够更直观地了解,本文就来详细为大家介绍一下利用Hostinger Ansible collection管理其VPS教程。
一、Hostinger VPS主机介绍
Hostinger VPS是一种功能强大的基于KVM的服务器,提供丰富的配置方案可选,同时VPS的机房位置众多,包括法国、立陶宛、印度、美国和巴西,其中最热门的就是机房位于美国地区的美国VPS,当然用户也可以根据自身的需求选择合适的机房位置。
Hostinger VPS提供多种KVM 1、KVM 2、KVM 4和KVM 8多种方案类型,其中最基础的配置为1核4G、50GB NVMe硬盘、4TB流量、Linux操作系统,价格低至36.99元/月。
折扣获取页面:Hostinger优惠码(购买时长越长,折扣优惠越大)
方案 | CPU | 内存 | 硬盘 | 流量 | 价格/月 |
KVM 1 | 1核 | 4GB | 50GB | 4TB | 36.99元 |
KVM 2 | 2核 | 8GB | 100GB | 8TB | 51.99元 |
KVM 4 | 4核 | 16GB | 200GB | 16TB | 73.99元 |
KVM 8 | 8核 | 32GB | 400GB | 32TB | 146.99元 |
《点击进入官网选购》
用户可以在Hostinger处购买一个VPS,并配置它。详情参考:《2025Hostinger主机最新设置教程》
二、安装Hostinger Ansible collection用户可以使用Ansible Galaxy(Ansible集合的官方仓库)安装Hostinger Ansible集合。
从Ansible Galaxy安装
ansible-galaxy collection install hostinger.vps
在本地安装开发
ansible-galaxy collection build
ansible-galaxy collection install hostinger-vps-*.tar.gz
如果用户想为集合做出贡献或需要从本地构建中安装它:
可用模块
Hostinger Ansible collection包括一套全面的模块,涵盖VPS管理的各个方面,从防火墙配置和电源管理到安装后脚本和快照。其中一些关键模块包括:
- VPS配置和电源管理
- 防火墙管理和规则
- 主机名和SSH密钥配置
- 安装后脚本管理
- 快照创建和恢复
此外,该集合还提供了一个动态清单插件,可自动发现用户的Hostinger VPS实例。
三、Hostinger Ansible使用教程要使用Hostinger Ansible集合,用户必须用自己的Hostinger API凭证配置Ansible环境。
API认证
在用户的Ansible项目中创建一个配置文件(例如hostinger_api.yaml):
yaml--- hostinger_api_token: "your_api_token_here"
然后,用户可以在剧本中引用这个文件,或者使用vars_files指令包含它。
使用示例
下面是一些如何在用户的剧本中使用Hostinger Ansible集合的实用示例。
1、检索VPS信息
---
- name: Get VPS Information
hosts: localhost
vars_files:
- hostinger_api.yaml
tasks:
- name: Get VPS details
hostinger.vps.hostinger_vps_get_info:
token: "{{ hostinger_api_token }}"
vps_id: 123456
register: vps_info
- name: Display VPS information
debug:
var: vps_info
2、重新启动VPS
---
- name: Restart VPS
hosts: localhost
vars_files:
- hostinger_api.yaml
tasks:
- name: Restart VPS
hostinger.vps.hostinger_vps_power:
token: "{{ hostinger_api_token }}"
vps_id: 123456
state: restarted
register: restart_result
- name: Display restart result
debug:
var: restart_result
3、创建和使用后安装脚本
---
- name: Manage Post-Install Scripts
hosts: localhost
vars_files:
- hostinger_api.yaml
tasks:
- name: Create LAMP stack post-install script
hostinger.vps.hostinger_vps_postinstall_create:
token: "{{ hostinger_api_token }}"
name: "Install Docker"
content: |
#!/bin/bash
apt update && apt install -y docker.io
register: post_install_script
- name: Reinstall VPS with post-install script
hostinger.vps.hostinger_vps_reinstall:
token: "{{ hostinger_api_token }}"
vps_id: 123456
template_id: 4 # Ubuntu 22.04
post_install_script_id: "{{ post_install_script.id }}"
相关推荐:《Hostinger VPS方案选择指南》
(本文由美国主机侦探原创,转载请注明出处“美国主机侦探”和原文地址!)

微信扫码加好友进群
主机优惠码及时掌握

QQ群号:938255063
主机优惠发布与交流