From f35776479ed4b0c78cf18b964762bd3650e650cd Mon Sep 17 00:00:00 2001 From: Neil Hanlon Date: Thu, 7 Apr 2022 01:32:47 -0400 Subject: [PATCH] add bootstrapping for the cloud --- ansible/playbooks/bootstrap-cloud.yml | 65 ++++++++++++++++++++++++ ansible/playbooks/tasks/infra-host.yml | 21 ++++---- ansible/playbooks/tasks/init-nodes.yml | 6 --- ansible/playbooks/tasks/upload_image.yml | 18 +++++++ ansible/roles/requirements.yml | 1 + ansible/scripts/clouds.py | 24 +++++++++ 6 files changed, 118 insertions(+), 17 deletions(-) create mode 100644 ansible/playbooks/bootstrap-cloud.yml create mode 100644 ansible/playbooks/tasks/upload_image.yml create mode 100644 ansible/scripts/clouds.py diff --git a/ansible/playbooks/bootstrap-cloud.yml b/ansible/playbooks/bootstrap-cloud.yml new file mode 100644 index 0000000..d2968a5 --- /dev/null +++ b/ansible/playbooks/bootstrap-cloud.yml @@ -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 diff --git a/ansible/playbooks/tasks/infra-host.yml b/ansible/playbooks/tasks/infra-host.yml index 84936d0..1ac5dd3 100644 --- a/ansible/playbooks/tasks/infra-host.yml +++ b/ansible/playbooks/tasks/infra-host.yml @@ -35,17 +35,16 @@ creates: /etc/openstack_deploy/user_secrets.yml.tar when: aio_install is undefined | default(false) -- import_tasks: tasks/python3-lxc.yml + #- import_tasks: tasks/python3-lxc.yml -- name: - copy: - content: "" - dest: /usr/share/lxc/config/rockylinux.common.conf - mode: '0644' - owner: root - group: root - - tags: python3-lxc + #- name: + # copy: + # content: "" + # dest: /usr/share/lxc/config/rockylinux.common.conf + # mode: '0644' + # owner: root + # group: root + # tags: python3-lxc - name: "[AIO] Deploy and setup configuration / bootstrap" when: aio_install | default('false') | bool @@ -61,7 +60,7 @@ chdir: /opt/openstack-ansible/ creates: /etc/openstack_deploy/ environment: - SCENARIO: "{{ SCENARIO | default('aio_lxc') }}" + SCENARIO: "{{ SCENARIO | default('aio_metal') }}" tags: - bootstrap - aio diff --git a/ansible/playbooks/tasks/init-nodes.yml b/ansible/playbooks/tasks/init-nodes.yml index 3b07706..6781375 100644 --- a/ansible/playbooks/tasks/init-nodes.yml +++ b/ansible/playbooks/tasks/init-nodes.yml @@ -97,12 +97,6 @@ version: 'master' 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 ansible.builtin.user: name: root diff --git a/ansible/playbooks/tasks/upload_image.yml b/ansible/playbooks/tasks/upload_image.yml new file mode 100644 index 0000000..0e80aaf --- /dev/null +++ b/ansible/playbooks/tasks/upload_image.yml @@ -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 }}" diff --git a/ansible/roles/requirements.yml b/ansible/roles/requirements.yml index f06d9e2..d033c2a 100644 --- a/ansible/roles/requirements.yml +++ b/ansible/roles/requirements.yml @@ -5,3 +5,4 @@ collections: - name: ansible.posix - name: ansible.utils - name: netbox.netbox + - name: openstack.cloud diff --git a/ansible/scripts/clouds.py b/ansible/scripts/clouds.py new file mode 100644 index 0000000..c29576a --- /dev/null +++ b/ansible/scripts/clouds.py @@ -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))