Skip to content

Commit

Permalink
Add epicli versioning (hitachienergy#1306)
Browse files Browse the repository at this point in the history
* Add version info file creation for each VM used.
  • Loading branch information
sbbroot committed Oct 1, 2021
1 parent 1f9fb7f commit 616fa62
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-1.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added

- [#1306](https://github.com/epiphany-platform/epiphany/issues/1306) - Allow to check on VMs which epicli version was used to deploy/upgrade components
- [#1487](https://github.com//epiphany-platform/epiphany/issues/1487) - Add RabbitMQ monitoring
- [#2600](https://github.com/epiphany-platform/epiphany/issues/2600) - Change epicli output structure

Expand Down
10 changes: 7 additions & 3 deletions core/src/epicli/cli/engine/ansible/AnsibleCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ def run_task_with_retries(self, inventory, module, hosts, retries, timeout=10, a
else:
raise Exception(f'Failed running task after {str(retries)} retries')

def run_playbook(self, inventory, playbook_path, vault_file=None):
def run_playbook(self, inventory, playbook_path, vault_file=None, extra_vars=None):
cmd = ['ansible-playbook']

if inventory is not None and len(inventory) > 0:
cmd.extend(["-i", inventory])
cmd.extend(['-i', inventory])

if vault_file is not None:
cmd.extend(["--vault-password-file", vault_file])
cmd.extend(['--vault-password-file', vault_file])

if extra_vars is not None:
variables = ' '.join([f"{variable}='{value}'" for variable, value in extra_vars.items()])
cmd.extend(['--extra-vars', f'"{variables}"'])

cmd.append(playbook_path)

Expand Down
17 changes: 16 additions & 1 deletion core/src/epicli/cli/engine/ansible/AnsibleRunner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import os
import time
import shutil
import time

from cli.engine.ansible.AnsibleCommand import AnsibleCommand
from cli.engine.ansible.AnsibleInventoryCreator import AnsibleInventoryCreator
Expand All @@ -14,6 +15,7 @@
from cli.helpers.naming_helpers import to_role_name
from cli.helpers.data_loader import DATA_FOLDER_PATH
from cli.helpers.Config import Config
from cli.version import VERSION


class AnsibleRunner(Step):
Expand Down Expand Up @@ -121,6 +123,13 @@ def apply(self):
# pre-flight to prepare machines
self.pre_flight(inventory_path)

self.ansible_command.run_playbook(inventory=inventory_path,
playbook_path=self.playbook_path(to_role_name('versioning')),
vault_file=Config().vault_password_location,
extra_vars={'mode': 'apply',
'date': datetime.datetime.now().ctime(),
'version': VERSION})

# run roles
enabled_roles = inventory_creator.get_enabled_roles()
for role in enabled_roles:
Expand Down Expand Up @@ -152,6 +161,12 @@ def upgrade(self):
# pre-flight to prepare machines
self.pre_flight(inventory_path)

self.ansible_command.run_playbook(inventory=inventory_path,
playbook_path=self.playbook_path(to_role_name('versioning')),
extra_vars={'mode': 'upgrade',
'date': datetime.datetime.now().ctime(),
'version': VERSION})

# run image_registry playbook
self.ansible_command.run_playbook(inventory=inventory_path,
playbook_path=self.playbook_path('image_registry'))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- name: Create versioning directory if it does not exist.
file:
path: /etc/epicli
state: directory
mode: '0755'

- name: Get versioning file status.
stat:
path: /etc/epicli/version
register: versioning_file

- name: Create versioning file.
copy:
dest: /etc/epicli/version
content: |
#mode | date | version
when: not versioning_file.stat.exists

- name: Append versioning info.
lineinfile:
path: /etc/epicli/version
line: "{{ mode }} | {{ date }} | {{ version }}"
9 changes: 9 additions & 0 deletions core/src/epicli/data/common/ansible/playbooks/versioning.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Ansible playbook for adding epicli version info for each component used

- hosts: all
become: true
become_method: sudo
tasks:
- import_role:
name: versioning

0 comments on commit 616fa62

Please sign in to comment.