add bootstrapping for the cloud
This commit is contained in:
parent
4f0bb1f4af
commit
f35776479e
65
ansible/playbooks/bootstrap-cloud.yml
Normal file
65
ansible/playbooks/bootstrap-cloud.yml
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
---
|
||||||
|
- name: Bootstrap our cloud with stuff
|
||||||
|
hosts: "{{ host | default('infra1') }}" # Go on infra host by default
|
||||||
|
become: true
|
||||||
|
|
||||||
|
handlers:
|
||||||
|
- import_tasks: handlers/main.yml
|
||||||
|
|
||||||
|
pre_tasks:
|
||||||
|
- name: Check if ansible cannot be run here
|
||||||
|
stat:
|
||||||
|
path: /etc/no-ansible
|
||||||
|
register: no_ansible
|
||||||
|
|
||||||
|
- name: Verify if we can run ansible
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "not no_ansible.stat.exists"
|
||||||
|
success_msg: "We are able to run on this node"
|
||||||
|
fail_msg: "/etc/no-ansible exists - skipping run on this node"
|
||||||
|
|
||||||
|
- name: Loading Variables from OS Common
|
||||||
|
import_tasks: tasks/common_vars.yml
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: setup flavors
|
||||||
|
openstack.cloud.compute_flavor:
|
||||||
|
cloud: linuxadminbooks
|
||||||
|
state: present
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
ram: "{{ item.ram }}"
|
||||||
|
vcpus: "{{ item.vcpus }}"
|
||||||
|
disk: "{{ item.disk }}"
|
||||||
|
ephemeral: "{{ item.ephemeral }}"
|
||||||
|
is_public: yes
|
||||||
|
tags: flavors
|
||||||
|
# yamllint disable rule:braces
|
||||||
|
loop:
|
||||||
|
- { name: 'tiny', ram: 1024, vcpus: 1, disk: 10, ephemeral: 10 }
|
||||||
|
- { name: 'small', ram: 2048, vcpus: 1, disk: 20, ephemeral: 20 }
|
||||||
|
- { name: 'medium', ram: 4096, vcpus: 2, disk: 20, ephemeral: 40 }
|
||||||
|
- { name: 'large', ram: 8192, vcpus: 4, disk: 20, ephemeral: 80 }
|
||||||
|
- { name: 'xlarge', ram: 16384, vcpus: 8, disk: 20, ephemeral: 100 }
|
||||||
|
# yamllint enable rule:braces
|
||||||
|
|
||||||
|
- name: setup images
|
||||||
|
include_tasks: tasks/upload_image.yml
|
||||||
|
tags: images
|
||||||
|
args:
|
||||||
|
apply:
|
||||||
|
tags: images
|
||||||
|
# yamllint disable rule:braces
|
||||||
|
loop:
|
||||||
|
- { name: 'cirros', filename: 'http://download.cirros-cloud.net/0.5.1/cirros-0.5.1-x86_64-disk.img', properties: {cpu_arch: x86_64, distro: cirros}}
|
||||||
|
- { name: 'rockylinux85', filename: 'https://dl.rockylinux.org/pub/rocky/8/images/Rocky-8-GenericCloud-8.5-20211114.2.x86_64.qcow2', properties: {cpu_arch: x86_64, distro: rocky}}
|
||||||
|
# yamllint enable rule:braces
|
||||||
|
|
||||||
|
post_tasks:
|
||||||
|
- name: Touching run file that ansible has ran here
|
||||||
|
file:
|
||||||
|
path: /var/log/ansible.run
|
||||||
|
state: touch
|
||||||
|
mode: '0644'
|
||||||
|
owner: root
|
||||||
|
group: root
|
@ -35,17 +35,16 @@
|
|||||||
creates: /etc/openstack_deploy/user_secrets.yml.tar
|
creates: /etc/openstack_deploy/user_secrets.yml.tar
|
||||||
when: aio_install is undefined | default(false)
|
when: aio_install is undefined | default(false)
|
||||||
|
|
||||||
- import_tasks: tasks/python3-lxc.yml
|
#- import_tasks: tasks/python3-lxc.yml
|
||||||
|
|
||||||
- name:
|
#- name:
|
||||||
copy:
|
# copy:
|
||||||
content: ""
|
# content: ""
|
||||||
dest: /usr/share/lxc/config/rockylinux.common.conf
|
# dest: /usr/share/lxc/config/rockylinux.common.conf
|
||||||
mode: '0644'
|
# mode: '0644'
|
||||||
owner: root
|
# owner: root
|
||||||
group: root
|
# group: root
|
||||||
|
# tags: python3-lxc
|
||||||
tags: python3-lxc
|
|
||||||
|
|
||||||
- name: "[AIO] Deploy and setup configuration / bootstrap"
|
- name: "[AIO] Deploy and setup configuration / bootstrap"
|
||||||
when: aio_install | default('false') | bool
|
when: aio_install | default('false') | bool
|
||||||
@ -61,7 +60,7 @@
|
|||||||
chdir: /opt/openstack-ansible/
|
chdir: /opt/openstack-ansible/
|
||||||
creates: /etc/openstack_deploy/
|
creates: /etc/openstack_deploy/
|
||||||
environment:
|
environment:
|
||||||
SCENARIO: "{{ SCENARIO | default('aio_lxc') }}"
|
SCENARIO: "{{ SCENARIO | default('aio_metal') }}"
|
||||||
tags:
|
tags:
|
||||||
- bootstrap
|
- bootstrap
|
||||||
- aio
|
- aio
|
||||||
|
@ -97,12 +97,6 @@
|
|||||||
version: 'master'
|
version: 'master'
|
||||||
tags: repos
|
tags: repos
|
||||||
|
|
||||||
- name: fetch patch
|
|
||||||
ansible.builtin.shell: 'git fetch https://review.opendev.org/openstack/openstack-ansible refs/changes/73/823573/13 && git checkout FETCH_HEAD'
|
|
||||||
args:
|
|
||||||
chdir: /opt/openstack-ansible/
|
|
||||||
|
|
||||||
|
|
||||||
- name: Create ssh key for root
|
- name: Create ssh key for root
|
||||||
ansible.builtin.user:
|
ansible.builtin.user:
|
||||||
name: root
|
name: root
|
||||||
|
18
ansible/playbooks/tasks/upload_image.yml
Normal file
18
ansible/playbooks/tasks/upload_image.yml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
- name: "[Upload Image] Download image - {{ item.filename }}"
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: "{{ item.filename }}"
|
||||||
|
dest: "/tmp/{{ item.filename | checksum }}"
|
||||||
|
|
||||||
|
- name: Upload image to openstack
|
||||||
|
openstack.cloud.image:
|
||||||
|
cloud: linuxadminbooks
|
||||||
|
state: present
|
||||||
|
is_public: yes
|
||||||
|
name: "{{ item.name }}"
|
||||||
|
container_format: "{{ item.containerformat | default('bare') }}" #bare
|
||||||
|
disk_format: "{{ item.diskformat | default('qcow2') }}" # qcow2
|
||||||
|
filename: "/tmp/{{ item.filename | checksum }}"
|
||||||
|
tags:
|
||||||
|
- custom
|
||||||
|
properties: "{{ item.properties }}"
|
@ -5,3 +5,4 @@ collections:
|
|||||||
- name: ansible.posix
|
- name: ansible.posix
|
||||||
- name: ansible.utils
|
- name: ansible.utils
|
||||||
- name: netbox.netbox
|
- name: netbox.netbox
|
||||||
|
- name: openstack.cloud
|
||||||
|
24
ansible/scripts/clouds.py
Normal file
24
ansible/scripts/clouds.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Adapted From http://adam.younglogic.com/2022/03/generating-a-clouds-yaml-file/ - collected 2022-04-07
|
||||||
|
"""
|
||||||
|
import os, yaml
|
||||||
|
|
||||||
|
clouds = {
|
||||||
|
"clouds":{
|
||||||
|
"linuxadminbooks": {
|
||||||
|
"auth" : {
|
||||||
|
"auth_url" : os.environ["OS_AUTH_URL"],
|
||||||
|
"project_name": os.environ["OS_PROJECT_NAME"],
|
||||||
|
"project_domain_name": os.environ["OS_PROJECT_DOMAIN_NAME"],
|
||||||
|
"username": os.environ["OS_USERNAME"],
|
||||||
|
"user_domain_name": os.environ["OS_USER_DOMAIN_NAME"],
|
||||||
|
"password": os.environ["OS_PASSWORD"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print(yaml.dumps(clouds))
|
Loading…
Reference in New Issue
Block a user