Rewrite Vagrant file using ansible and Centos 8

Depends-On: Ifa876b3e5f89258f40055fa7ce03f5e9c601771c
Change-Id: I806c76bff85210f74cd23c29835f41c174b8c960
This commit is contained in:
Federico Ressi
2020-06-19 07:35:35 +02:00
parent bb0a45ffde
commit 07e593f829
21 changed files with 389 additions and 99 deletions

View File

@@ -0,0 +1,3 @@
---
resolv_conf_file: '/etc/resolv.conf'

View File

@@ -0,0 +1,10 @@
---
- name: copy '{{ resolv_conf_file}}' file
become: yes
copy:
src: '{{ resolv_conf_file}}'
dest: /etc/resolv.conf
owner: root
group: root
mode: '0644'

View File

@@ -0,0 +1,13 @@
---
devstack_dest_dir: /opt/stack
devstack_dir: '{{ devstack_dest_dir }}/devstack'
devstack_git_repo: 'http://opendev.org/openstack/devstack'
devstack_git_version: 'master'
devstack_local_conf_file: 'local.conf'
devstack_requirements_dir: '{{ devstack_dest_dir }}/requirements'
devstack_tobiko_dir: '{{ devstack_dest_dir }}/tobiko'
devstack_src_dir: '{{ devstack_workspace_dir }}/devstack'
sudo_secure_path: '/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

View File

@@ -0,0 +1,4 @@
---
dependencies:
- tobiko-common

View File

@@ -0,0 +1,51 @@
---
- name: "check '{{ devstack_src_dir }}' exists"
stat:
path: '{{ devstack_src_dir }}'
delegate_to: localhost
register: check_devstack_src_dir_exists
when: "(devstack_src_dir | length) > 0"
failed_when: no
- name: "ensure '{{ devstack_dir }}' exists"
become: yes
become_user: root
file:
path: '{{ devstack_dir | realpath }}'
state: directory
mode: '0755'
owner: stack
group: stack
recurse: yes
- become: yes
become_user: stack
block:
- name: "copy '{{ devstack_src_dir }}' to '{{ devstack_dir }}'"
synchronize:
group: no
owner: no
src: "{{ devstack_src_dir | realpath }}/."
dest: "{{ devstack_dir | realpath }}"
use_ssh_args: yes
recursive: yes
rsync_opts:
- '--exclude-from={{ devstack_src_dir | realpath }}/.gitignore'
register: copy_devstack_src_dir
when: check_devstack_src_dir_exists.stat.isdir | default(False)
- name: fetch DevStack sources from '{{ devstack_git_repo }}'
git:
repo: '{{ devstack_git_repo }}'
dest: '{{ devstack_dir }}'
version: '{{ devstack_git_version }}'
when: copy_devstack_src_dir is skipped
- name: copy local.conf file
copy:
src: '{{ devstack_local_conf_file }}'
dest: '{{ devstack_dir }}/local.conf'

View File

@@ -0,0 +1,34 @@
---
- name: "check '{{ requirements_src_dir }}' exists"
stat:
path: '{{ requirements_src_dir }}'
delegate_to: localhost
register: check_requirements_src_dir_exists
- name: "ensure '{{ devstack_tobiko_dir }}' exists"
become: yes
become_user: root
file:
path: '{{ devstack_requirements_dir | realpath }}'
state: directory
mode: '0755'
owner: stack
group: stack
- name: "copy '{{ requirements_src_dir }}' to '{{ devstack_requirements_dir }}'"
become: yes
become_user: stack
synchronize:
group: no
owner: no
src: "{{ requirements_src_dir | realpath }}/."
dest: "{{ devstack_requirements_dir | realpath }}"
use_ssh_args: yes
recursive: yes
rsync_opts:
- '--exclude-from={{ tobiko_src_dir | realpath }}/.gitignore'
register: copy_requirements_src_dir
when: check_requirements_src_dir_exists.stat.isdir | default(False)

View File

@@ -0,0 +1,35 @@
---
- name: "check '{{ tobiko_src_dir }}' exists"
stat:
path: '{{ tobiko_src_dir }}'
delegate_to: localhost
register: check_tobiko_src_dir_exists
- name: "ensure '{{ devstack_tobiko_dir }}' exists"
become: yes
become_user: root
file:
path: '{{ devstack_tobiko_dir | realpath }}'
state: directory
mode: '0755'
owner: stack
group: stack
recurse: yes
- name: "copy '{{ tobiko_src_dir }}' to '{{ devstack_tobiko_dir }}'"
become: yes
become_user: stack
synchronize:
group: no
owner: no
src: "{{ tobiko_src_dir | realpath }}/."
dest: "{{ devstack_tobiko_dir | realpath }}"
use_ssh_args: yes
recursive: yes
rsync_opts:
- '--exclude-from={{ tobiko_src_dir | realpath }}/.gitignore'
register: copy_tobiko_src_dir
when: check_tobiko_src_dir_exists.stat.isdir | default(False)

View File

@@ -0,0 +1,45 @@
---
- name: ensure /usr/local/bin is in sudo secure path
become: yes
lineinfile:
path: /etc/sudoers
regexp: 'secure_path'
line: 'Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin'
validate: '/usr/sbin/visudo -cf %s'
- name: ensure stack group exists
become: yes
group:
name: stack
state: present
- name: ensure stack user exists
become: yes
user:
name: stack
home: '{{ devstack_dest_dir }}'
comment: DevStack user
group: stack
shell: /bin/bash
- name: ensure stack user has sudo privileges
become: yes
copy:
dest: /etc/sudoers.d/stack
content: |
stack ALL=(ALL) NOPASSWD: ALL
- name: ensure stack user home exists
become: yes
become_user: root
file:
path: '{{ devstack_dest_dir | realpath }}'
state: directory
mode: '0755'
owner: stack
group: stack

View File

@@ -0,0 +1,13 @@
---
- name: "ensure DevStack bindeps are installed"
become: true
package:
name:
- git
- iptables
- python3
- python3-pip
- python3-systemd
- rsync
- sudo

View File

@@ -0,0 +1,9 @@
---
- include_tasks: install-bindeps.yaml
- include_tasks: ensure-stack-user.yaml
- include_tasks: run-unstack.yaml
- include_tasks: deploy-devstack.yaml
- include_tasks: deploy-requirements.yaml
- include_tasks: deploy-tobiko.yaml
- include_tasks: run-stack.yaml

View File

@@ -0,0 +1,16 @@
---
- name: run stack.sh
become: yes
become_user: stack
command:
cmd: /bin/bash ./stack.sh
chdir: '{{ devstack_dir }}'
executable: '/bin/bash'
register: run_stack
ignore_errors: yes
- name: show stack.sh output
debug: var=run_stack.stderr_lines
failed_when: yes

View File

@@ -0,0 +1,23 @@
---
- name: check '{{ devstack_dir }}/local.conf' exists
stat:
path: '{{ devstack_dir }}/local.conf'
register: check_devstack_local_conf_file_exists
failed_when: no
- name: run unstack.sh
become: yes
become_user: stack
command:
cmd: /bin/bash ./unstack.sh
chdir: '{{ devstack_dir }}'
register: run_unstack
ignore_errors: yes
when:
check_devstack_local_conf_file_exists.stat.exists | default(False)
- debug: var=run_unstack.stderr_lines
when: run_unstack is failed

View File

@@ -15,11 +15,6 @@
register: install_python_packages
- name: "show installed packages"
debug: var=install_python_packages.changes
when: install_python_packages is changed
- name: "compile python 3 from sources"
include_role: name=tobiko-compile-python
when:

View File

@@ -0,0 +1,3 @@
---
ssh_key_file: '{{ playbook_dir }}/ssh_identity'

View File

@@ -0,0 +1,22 @@
---
- name: "generate local SSH key '{{ ssh_key_file }}'"
openssh_keypair:
path: '{{ ssh_key_file }}'
type: rsa
size: 4096
state: present
force: no
delegate_to: localhost
- name: "copy '{{ ssh_key_file }}' file to host"
copy:
src: '{{ ssh_key_file }}{{ item }}'
dest: '/home/vagrant/.ssh/id_rsa{{ item }}'
owner: vagrant
group: vagrant
mode: '0600'
loop:
- ''
- '.pub'

View File

@@ -0,0 +1,5 @@
---
redhat_activationkey:
redhat_username:
redhat_password:

View File

@@ -0,0 +1,13 @@
---
- name: subscribe to Red Hat repositories
become: yes
redhat_subscription:
state: present
activationkey: '{{ redhat_activationkey or omit }}'
username: '{{ redhat_username or omit }}'
password: '{{ redhat_password or omit }}'
auto_attach: yes
when:
- ansible_distribution == 'RedHat'
- redhat_activationkey or redhat_username