Skip to content

Commit

Permalink
ansible installation [wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
Limmen committed Mar 11, 2024
1 parent 79cb15b commit 4dd1443
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions ansible/install_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
become: true
apt:
name: build-essential
update_cache: yes

- name: Installation of make
become: true
Expand Down
3 changes: 2 additions & 1 deletion ansible/start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

source ~/.bashrc
~/anaconda3/bin/activate $1
csle stop clustermanager
sleep 2
csle start clustermanager
Expand Down
19 changes: 17 additions & 2 deletions ansible/start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,20 @@

tasks:

- name: Start services
script: ./start.sh
- name: Restart postgres
become: true
service:
name: postgresql
state: restarted

- name: Change permissions on start script
become: true
command: sudo chmod -R u+rwx "/home/{{ user }}/csle/ansible/start.sh"

- hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Execute script
command: "python /home/{{ user }}/csle/ansible/start_services.py {{ leader_ip }} {{ user }} {{ conda_environment_name }}"
register: script_output
13 changes: 13 additions & 0 deletions ansible/start_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import paramiko
import time
import sys

if __name__ == '__main__':
ip = sys.argv[1]
user = sys.argv[2]
conda_env = sys.argv[3]
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=ip, port=22, username=user)
stdin, stdout, stderr = ssh_client.exec_command(f"bash -ic 'nohup ~/csle/ansible/start.sh {conda_env} &'", get_pty=True)
time.sleep(120)
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def start_client_manager(emulation_env_config: EmulationEnvConfig, logger: loggi
)
o, e, _ = EmulationUtil.execute_ssh_cmd(cmd=cmd, conn=emulation_env_config.get_connection(
ip=emulation_env_config.traffic_config.client_population_config.docker_gw_bridge_ip))
time.sleep(2)
time.sleep(5)
return True
return False

Expand Down

0 comments on commit 4dd1443

Please sign in to comment.