initial checkin
This commit is contained in:
commit
8abe93f1c9
|
@ -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).
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
# defaults file for role_pve-deploy
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
# handlers file for role_pve-deploy
|
|
@ -0,0 +1,52 @@
|
|||
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.1
|
||||
|
||||
# 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.
|
|
@ -0,0 +1,186 @@
|
|||
---
|
||||
# tasks file for role_pve-deploy
|
||||
|
||||
################################################
|
||||
- name: Download OS Template
|
||||
get_url:
|
||||
url: "http://download.proxmox.com/images/system/{{ ct_template }}"
|
||||
dest: "/var/lib/vz/template/cache/{{ ct_template }}"
|
||||
when: host_type == "Container"
|
||||
delegate_to: reddwarf
|
||||
|
||||
#####################################################################################
|
||||
# Container creation
|
||||
|
||||
- debug: msg="Deploying new container..."
|
||||
|
||||
- name: Create Container
|
||||
community.general.proxmox:
|
||||
vmid: "{{ ctid }}"
|
||||
node: "{{ node }}"
|
||||
api_user: "{{ api_user }}"
|
||||
api_password: "{{ api_password }}"
|
||||
api_host: "{{ api_host }}"
|
||||
hostname: "{{ guest_name }}"
|
||||
password: "{{ ctpassword }}"
|
||||
# commented out to use host searchdomain and nameservers
|
||||
#searchdomain: "{{ searchdomain }}"
|
||||
#nameserver: "{{ ctnameserver }}"
|
||||
cores: "{{ cpu_num }}"
|
||||
swap: "{{ ctswap }}"
|
||||
memory: "{{ mem_size }}"
|
||||
disk: "{{ root_size }}"
|
||||
storage: "{{ ctstorage }}"
|
||||
netif: '{"net0":"name=eth0,ip={{ guest_ip_cidr }},gw={{ guest_gw }},bridge={{ ctbridge }},type=veth,firewall=1"}'
|
||||
ostemplate: 'local:vztmpl/{{ ct_template }}'
|
||||
features:
|
||||
- nesting=1
|
||||
unprivileged: true
|
||||
onboot: true
|
||||
state: present
|
||||
when: host_type == "Container"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- name: Start Container
|
||||
community.general.proxmox:
|
||||
vmid: "{{ ctid }}"
|
||||
node: "{{ node }}"
|
||||
api_user: "{{ api_user }}"
|
||||
api_password: "{{ api_password }}"
|
||||
api_host: "{{ api_host }}"
|
||||
state: started
|
||||
timeout: 90
|
||||
when: host_type == "Container"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- debug: msg="waiting 15 seconds for guest container to start"
|
||||
when: host_type == "Container"
|
||||
|
||||
- name: waited 15 seconds for guest container to start
|
||||
wait_for:
|
||||
timeout: 15
|
||||
when: host_type == "Container"
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Configure sshd to allow root ssh key access (Container)
|
||||
shell:
|
||||
cmd: pct exec {{ ctid }} -- bash -c "echo 'PermitRootLogin prohibit-password' >>/etc/ssh/sshd_config"
|
||||
when: host_type == "Container"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- name: Add ssh keys to root authorized_keys (Container)
|
||||
shell:
|
||||
cmd: pct exec {{ ctid }} -- bash -c "echo '{{ ssh_key_item.value }}' >>/root/.ssh/authorized_keys"
|
||||
loop_control:
|
||||
loop_var: ssh_key_item
|
||||
with_items: "{{ ssh-pub-keys | default({}) | dict2items }}"
|
||||
when: host_type == "Container"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- name: Fix perms on root authorized_keys (Container)
|
||||
shell:
|
||||
cmd: pct exec {{ ctid }} -- bash -c "chmod 600 /root/.ssh/authorized_keys"
|
||||
when: host_type == "Container"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- name: Restart sshd (Container)
|
||||
shell:
|
||||
cmd: pct exec {{ ctid }} -- bash -c "systemctl restart ssh"
|
||||
when: host_type == "Container"
|
||||
delegate_to: reddwarf
|
||||
|
||||
#####################################################################################
|
||||
# VM creation
|
||||
|
||||
- debug: msg="Deploying new VM..."
|
||||
- name: Clone template to new VM
|
||||
community.general.proxmox_kvm:
|
||||
newid: "{{ ctid }}"
|
||||
node: "{{ node }}"
|
||||
api_user: "{{ api_user }}"
|
||||
api_password: "{{ api_password }}"
|
||||
api_host: "{{ api_host }}"
|
||||
clone: "{{ vm_template }}"
|
||||
name: "{{ guest_name }}"
|
||||
storage: "{{ ctstorage }}"
|
||||
format: qcow2
|
||||
timeout: 500
|
||||
memory: "{{ mem_size }}"
|
||||
cores: "{{ cpu_num }}"
|
||||
state: present
|
||||
when: host_type == "VM"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- name: Start VM
|
||||
community.general.proxmox_kvm:
|
||||
vmid: "{{ ctid }}"
|
||||
node: "{{ node }}"
|
||||
api_user: "{{ api_user }}"
|
||||
api_password: "{{ api_password }}"
|
||||
api_host: "{{ api_host }}"
|
||||
state: started
|
||||
timeout: 90
|
||||
when: host_type == "VM"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- debug: msg="waiting 30 seconds for guest VM to start"
|
||||
when: host_type == "VM"
|
||||
|
||||
- name: waited 30 seconds for guest VM to start
|
||||
wait_for:
|
||||
timeout: 30
|
||||
when: host_type == "VM"
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Configure sshd to allow root ssh key access (VM)
|
||||
shell:
|
||||
cmd: qm guest exec {{ ctid }} -- bash -c "echo 'PermitRootLogin prohibit-password' >>/etc/ssh/sshd_config"
|
||||
when: host_type == "VM"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- name: Add ssh keys to root authorized_keys (VM)
|
||||
shell:
|
||||
cmd: pct exec {{ ctid }} -- bash -c "echo '{{ ssh_key_item.value }}' >>/root/.ssh/authorized_keys"
|
||||
loop_control:
|
||||
loop_var: ssh_key_item
|
||||
with_items: "{{ ssh-pub-keys | default({}) | dict2items }}"
|
||||
when: host_type == "VM"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- name: Fix perms on root authorized_keys (VM)
|
||||
shell:
|
||||
cmd: qm guest exec {{ ctid }} -- bash -c "chmod 600 /root/.ssh/authorized_keys"
|
||||
when: host_type == "VM"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- name: Restart sshd (VM)
|
||||
shell:
|
||||
cmd: qm guest exec {{ ctid }} -- bash -c "systemctl restart ssh"
|
||||
when: host_type == "VM"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- name: update /etc/hostname (VM)
|
||||
shell:
|
||||
cmd: qm guest exec {{ ctid }} -- bash -c "sed -i 's/{{ vm_template }}/{{ guest_name }}/g' /etc/hostname"
|
||||
when: host_type == "VM"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- name: update /etc/hosts (VM)
|
||||
shell:
|
||||
cmd: qm guest exec {{ ctid }} -- bash -c "sed -i 's/{{ vm_template }}/{{ guest_name }}/g' /etc/hosts"
|
||||
when: host_type == "VM"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- name: update IP in /etc/network/interfaces (VM)
|
||||
shell:
|
||||
cmd: qm guest exec {{ ctid }} -- bash -c "sed -i 's/address {{ vm_template_ip }}/address {{ guest_ip }}/g' /etc/network/interfaces"
|
||||
when: host_type == "VM"
|
||||
delegate_to: reddwarf
|
||||
|
||||
- name: reboot guest VM
|
||||
shell:
|
||||
cmd: qm reboot {{ ctid }}
|
||||
when: host_type == "VM"
|
||||
delegate_to: reddwarf
|
||||
|
||||
# EOF
|
|
@ -0,0 +1,2 @@
|
|||
localhost
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
- hosts: localhost
|
||||
remote_user: root
|
||||
roles:
|
||||
- role_pve-deploy
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
# vars file for role_pve-deploy
|
||||
|
||||
ssh-pub-keys:
|
||||
delans: |
|
||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDMry9AQFLxX2QqqZLS/PDH/xRmK9CgGu3wDA/1+0lhLmqij/a125kHFwC16sdiwBfik1Tzj4yetZwzQ6xeNRZPevxhuB4FGVU/QHeDstCB9ASS0bM90DHEb205VrkVFz04VHN+7q9SvK23+xo5OvhOAwDuPJKNA62CJlgc46cvLaWup5an4xmir3lqUtI5N+oGwIBm36F/qZtvNwOhRkWbap50yrp60Ce3vdiugfQBliLzDMRKup4kjuCfYgwm0PHgRb796ttYmOXFKt+rnnD/MLaX5yRXAhbYZ/5jO+bAUu+kBWGt5hdeSk5m0Uu8mo9z4Xw5yNg6+DX9m+QL5HNwnz51PVMqCufGMz20430uL82fSjW1kGDe8I+5UyYjDfUUhwwAkxNdb8kGvU1OUYJxG7Kr/qN11W/kfsaJw/loK25Jwu5jg8ooJm6/9RiJEUmvP/0h4QDDWRZ9vORwIiRlLXZW8WAxP1KEuBxOuKp5Wt/fRTcdPU820Hp2v0IOX4E= rmorrow@delans
|
||||
kryten: |
|
||||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCgNeo2NotlS/WPoB/YTiSovxzR/puknjqsVBc16zS0xwBUD1fFQEVNypUtzSlWKy36wxX6YJsT7fBNkLq6QoY0FPbWa7l5KlUvHYASeMmZAH81pYPcMwhQverwmNjPoABYyzTe0658Qz6qbB8CTD+r4xKYCqELlk8VkLPSgA1jJsNaurHZS6iN0EgdqyZ57h1/sZi8laVBKcU9yH0UOro2o7Phxo3/vT7w7px2pyExXwYGwhKxuOaitdq9Gv8qDIwt46Gj5Wm5CqU2zzT1VBgTpnv5RcCKTA6HZgBLekFhZj42yMntDF+tTP6te85u1u6f6CbalyXBng+eUsN4qvM3fW1sIXiVLnOxSdQgTDPbTCh52QXuF36rEU1aSNd4DRtUmpwItBJpIwREJQ64gor88fpTiGpkQL0r15bdFlIjf2XjFexpj258eGUSKDluQq1cX/qi3Okvby32HW9L18HcC1FNee6V2+lyxt3DKg8Zbfk2TAaEtqJf3KpCsFMpGVE= rmorrow@kryten
|
||||
|
Loading…
Reference in New Issue