Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1136 from deNBI/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dweinholz authored Jun 24, 2022
2 parents 5362900 + 1d36eef commit 350b657
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 25 deletions.
2 changes: 1 addition & 1 deletion VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2712,7 +2712,7 @@ def update_playbooks(self):
self.ALL_TEMPLATES = [
name
for name in os.listdir(PLAYBOOKS_DIR)
if name != "packer" and os.path.isdir(os.path.join(PLAYBOOKS_DIR, name))
if name not in ["optional","packer",".github"] and os.path.isdir(os.path.join(PLAYBOOKS_DIR, name))
]
LOG.info(self.ALL_TEMPLATES)

Expand Down
37 changes: 17 additions & 20 deletions VirtualMachineService/ancon/Playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class Playbook(object):
PLAYBOOK_FAILED = "PLAYBOOK_FAILED"

def __init__(
self,
ip,
port,
playbooks_information,
osi_private_key,
public_key,
pool,
loaded_metadata_keys,
cloud_site,
self,
ip,
port,
playbooks_information,
osi_private_key,
public_key,
pool,
loaded_metadata_keys,
cloud_site,
):
self.loaded_metadata_keys = loaded_metadata_keys
self.cloud_site = cloud_site
Expand Down Expand Up @@ -87,12 +87,9 @@ def __init__(
mode="w+", dir=self.directory.name, delete=False
)

inventory_string = (
"[vm]\n" + ip + ":" + port + " ansible_user=ubuntu "
"ansible_ssh_private_key_file="
+ self.private_key.name
+ " ansible_python_interpreter=/usr/bin/python3"
)
inventory_string = f"[vm]\n" \
f"{ip} ansible_port={port} ansible_user=ubuntu ansible_ssh_private_key_file={self.private_key.name} ansible_python_interpreter=/usr/bin/python3"

self.inventory.write(inventory_string)
self.inventory.close()

Expand All @@ -107,12 +104,12 @@ def copy_playbooks_and_init(self, playbooks_information, public_key):
self.playbooks_dir + "/change_key_vars_file.yml", self.directory.name
)
with open(
self.directory.name + "/change_key_vars_file.yml", mode="r"
self.directory.name + "/change_key_vars_file.yml", mode="r"
) as key_file:
data_ck = self.yaml_exec.load(key_file)
data_ck["change_key_vars"]["key"] = public_key.strip('"')
with open(
self.directory.name + "/change_key_vars_file.yml", mode="w"
self.directory.name + "/change_key_vars_file.yml", mode="w"
) as key_file:
self.yaml_exec.dump(data_ck, key_file)
self.add_to_playbook_always_lists("change_key")
Expand All @@ -122,14 +119,14 @@ def copy_playbooks_and_init(self, playbooks_information, public_key):
self.playbooks_dir + "/" + self.playbook_exec_name, self.directory.name
)
with open(
self.directory.name + "/" + self.playbook_exec_name, mode="r"
self.directory.name + "/" + self.playbook_exec_name, mode="r"
) as generic_playbook:
data_gp = self.yaml_exec.load(generic_playbook)
data_gp[0]["vars_files"] = self.vars_files
data_gp[0]["tasks"][0]["block"] = self.tasks
data_gp[0]["tasks"][0]["always"] = self.always_tasks
with open(
self.directory.name + "/" + self.playbook_exec_name, mode="w"
self.directory.name + "/" + self.playbook_exec_name, mode="w"
) as generic_playbook:
self.yaml_exec.dump(data_gp, generic_playbook)

Expand Down Expand Up @@ -270,7 +267,7 @@ def get_logs(self):
return self.returncode, self.stdout, self.stderr

def cleanup(self, openstack_id):
self.directory.cleanup()
# self.directory.cleanup()
self.redis.delete(openstack_id)

def stop(self, openstack_id):
Expand Down
51 changes: 49 additions & 2 deletions VirtualMachineService/ancon/playbooks/generic_playbook.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,57 @@
- name: Setting up your virtual machine
hosts: all
hosts: vm
become: yes
connection: paramiko_ssh
gather_facts: yes
vars_files:
pre_tasks:
- name: PRE_TASK Disable unattended upgrades
lineinfile:
path: /etc/apt/apt.conf.d/10periodic
regexp: "^APT::Periodic::Unattended-Upgrade"
line: 'APT::Periodic::Unattended-Upgrade "0";'
create: yes
- name: PRE_TASK Stop apt-daily.* systemd services
service:
name: "{{ item }}"
state: stopped
with_items:
- unattended-upgrades
- apt-daily
- apt-daily.timer
- apt-daily-upgrade
- apt-daily-upgrade.timer

- name: PRE_TASK Wait for automatic system updates 1
shell: while sudo fuser /var/lib/dpkg/lock >/dev/null 2>&1; do sleep 1; done;

- name: PRE_TASK Wait for automatic system updates 2
shell: while sudo fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do sleep 1; done;

- name: PRE_TASK Update apt cache
become: true
apt:
upgrade: true
update_cache: true
autoremove: true
autoclean: true

tasks:
- name: Setting up your virtual machine
block:
always:

post_tasks:
- name: POST_TASK enable unattended upgrades
lineinfile:
path: /etc/apt/apt.conf.d/10periodic
regexp: "^APT::Periodic::Unattended-Upgrade"
line: 'APT::Periodic::Unattended-Upgrade "1";'
create: yes
- name: POST_TASK Start apt-daily.* systemd services
service:
name: "{{ item }}"
state: started
with_items:
- unattended-upgrades
- apt-daily
- apt-daily.timer
2 changes: 1 addition & 1 deletion ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[defaults]
host_key_checking = False
callbacks_enabled = ansible.posix.profile_tasks
callbacks_enabled = ansible.posix.profile_tasks, ansible.posix.timer
roles_path = ~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/code/VirtualMachineService/ancon/playbooks/roles


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ paramiko==2.11.0
ruamel.yaml==0.17.21
pyvim==3.0.3
redis==4.3.3
requests==2.27.1
requests==2.28.0
pyyaml==6.0

0 comments on commit 350b657

Please sign in to comment.