add ansible role

This commit is contained in:
2023-08-09 11:51:39 +03:00
parent 58e00cd820
commit 1426db5f82
18 changed files with 495 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@@ -0,0 +1,38 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

View File

@@ -0,0 +1,13 @@
---
pve_storage: local
api_host: 10.1.1.10
api_user: root@pam
api_password: P@ssw0rd
node: altv
key_name: id_rsa.pub
server_template: s-tmpl
ws_template: ws-tmpl
kws_template: kws-tmpl
vm_user: root
vm_password: P@ssw0rd

View File

@@ -0,0 +1,2 @@
---
# handlers file for deploy_vms

View File

@@ -0,0 +1,53 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.9
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@@ -0,0 +1,61 @@
---
- name: Серверы - Клонирование ВМ из шаблона
community.general.proxmox_kvm:
node: "{{ node }}"
name: "{{ item.value.name }}"
newid: "{{ item.value.vmid }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
api_host: "{{ api_host }}"
clone: "{{ server_template }}"
storage: "{{ pve_storage }}"
format: qcow2
timeout: 500
loop: "{{ lookup('dict', server_vms) }}"
- name: Серверы - Настройка IP адресов
command: "qm set {{ item.value.vmid }} --ipconfig0 gw={{ item.value.gw }},ip={{ item.value.ip }}"
loop: "{{ lookup('dict', server_vms) }}"
- name: Серверы - Настройка DNS
command: "qm set {{ item.value.vmid }} --nameserver {{ item.value.dns }}"
loop: "{{ lookup('dict', server_vms) }}"
- name: Серверы - Создание пользователя root
command: "qm set {{ item.value.vmid }} --ciuser {{ vm_user }}"
loop: "{{ lookup('dict', server_vms) }}"
- name: Серверы - Создание пароля пользователя root
command: "qm set {{ item.value.vmid }} --cipassword {{ vm_password }}"
loop: "{{ lookup('dict', server_vms) }}"
- name: Серверы - Копирование SSH ключей в ВМ
command: "qm set {{ item.value.vmid }} --sshkey {{ key_name }}"
args:
chdir: ~/.ssh
loop: "{{ lookup('dict', server_vms) }}"
- name: Серверы - Обновление параметров ВМ
community.general.proxmox_kvm:
api_host: "{{ api_host }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
cores: "{{ item.value.cores }}"
sockets: "{{ item.value.sockets }}"
memory: "{{ item.value.memory }}"
update: true
vmid: "{{ item.value.vmid }}"
node: "{{ node }}"
name: "{{ item.value.name }}"
loop: "{{ lookup('dict', server_vms) }}"
- name: Серверы - Запуск ВМ
community.general.proxmox_kvm:
api_host: "{{ api_host }}"
api_password: "{{ api_password }}"
api_user: "{{ api_user }}"
vmid: "{{ item.value.vmid }}"
node: "{{ node }}"
state: started
loop: "{{ lookup('dict', server_vms) }}"

View File

@@ -0,0 +1,61 @@
---
- name: Рабочая станция - Клонирование ВМ из шаблона
community.general.proxmox_kvm:
node: "{{ node }}"
name: "{{ item.value.name }}"
newid: "{{ item.value.vmid }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
api_host: "{{ api_host }}"
clone: "{{ server_template }}"
storage: "{{ pve_storage }}"
format: qcow2
timeout: 500
loop: "{{ lookup('dict', ws_vms) }}"
- name: Рабочая станция - Настройка IP адресов
command: "qm set {{ item.value.vmid }} --ipconfig0 gw={{ item.value.gw }},ip={{ item.value.ip }}"
loop: "{{ lookup('dict', server_vms) }}"
- name: Рабочая станция - Настройка DNS
command: "qm set {{ item.value.vmid }} --nameserver {{ item.value.dns }}"
loop: "{{ lookup('dict', ws_vms) }}"
- name: Рабочая станция - Создание пользователя root
command: "qm set {{ item.value.vmid }} --ciuser {{ vm_user }}"
loop: "{{ lookup('dict', ws_vms) }}"
- name: Рабочая станция - Создание пароля пользователя root
command: "qm set {{ item.value.vmid }} --cipassword {{ vm_password }}"
loop: "{{ lookup('dict', ws_vms) }}"
- name: Рабочая станция - Копирование SSH ключей в ВМ
command: "qm set {{ item.value.vmid }} --sshkey {{ key_name }}"
args:
chdir: ~/.ssh
loop: "{{ lookup('dict', ws_vms) }}"
- name: Рабочая станция - Обновление параметров ВМ
community.general.proxmox_kvm:
api_host: "{{ api_host }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
cores: "{{ item.value.cores }}"
sockets: "{{ item.value.sockets }}"
memory: "{{ item.value.memory }}"
update: true
vmid: "{{ item.value.vmid }}"
node: "{{ node }}"
name: "{{ item.value.name }}"
loop: "{{ lookup('dict', ws_vms) }}"
- name: Рабочая станция - Запуск ВМ
community.general.proxmox_kvm:
api_host: "{{ api_host }}"
api_password: "{{ api_password }}"
api_user: "{{ api_user }}"
vmid: "{{ item.value.vmid }}"
node: "{{ node }}"
state: started
loop: "{{ lookup('dict', ws_vms) }}"

View File

@@ -0,0 +1,7 @@
---
- name: Создание серверной группировки
include_tasks: tasks/deploy_servers.yml
- name: Создание клиентских рабочих станций
include_tasks: tasks/deploy_ws.yml

View File

@@ -0,0 +1,2 @@
localhost

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- deploy_vms

View File

@@ -0,0 +1,50 @@
---
server_vms:
alts1:
name: alts1.alt.lan
ip: 10.1.1.11/24
gw: 10.1.1.9
dns: 77.88.8.8
vmid: 201
cores: 2
sockets: 1
memory: 2048
alts2:
name: alts2.alt.lan
ip: 10.1.1.12/24
gw: 10.1.1.9
dns: 77.88.8.8
vmid: 202
cores: 2
sockets: 1
memory: 2048
alts3:
name: alts3.alt.lan
ip: 10.1.1.13/24
gw: 10.1.1.9
dns: 77.88.8.8
vmid: 203
cores: 2
sockets: 1
memory: 2048
ws_vms:
ws:
name: ws.alt.lan
ip: 10.1.1.14/24
gw: 10.1.1.9
dns: 77.88.8.8
vmid: 204
cores: 2
sockets: 1
memory: 2048
kws:
name: kws.alt.lan
ip: 10.1.1.15/24
gw: 10.1.1.9
dns: 77.88.8.8
vmid: 205
cores: 2
sockets: 1
memory: 2048