vm-tool 1.0.12__tar.gz → 1.0.14__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vm_tool-1.0.12/vm_tool.egg-info → vm_tool-1.0.14}/PKG-INFO +31 -1
- {vm_tool-1.0.12 → vm_tool-1.0.14}/README.md +31 -1
- {vm_tool-1.0.12 → vm_tool-1.0.14}/setup.py +1 -1
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool/cli.py +1 -1
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool/runner.py +42 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool/ssh.py +12 -12
- vm_tool-1.0.14/vm_tool/vm_setup/cloud_inventory.yml +8 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool/vm_setup/setup.yml +5 -12
- {vm_tool-1.0.12 → vm_tool-1.0.14/vm_tool.egg-info}/PKG-INFO +31 -1
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool.egg-info/SOURCES.txt +1 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/LICENSE +0 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/MANIFEST.in +0 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/setup.cfg +0 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool/__init__.py +0 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool/vm_setup/docker/create_docker_service.yml +0 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool/vm_setup/docker/install_docker_and_compose.yml +0 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool/vm_setup/inventory.yml +0 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool.egg-info/dependency_links.txt +0 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool.egg-info/entry_points.txt +0 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool.egg-info/requires.txt +0 -0
- {vm_tool-1.0.12 → vm_tool-1.0.14}/vm_tool.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: vm_tool
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.14
|
|
4
4
|
Summary: A Comprehensive Tool for Setting Up Virtual Machines Using Ansible.
|
|
5
5
|
License: MIT
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -65,6 +65,36 @@ By automating these tasks, the tool minimizes errors and saves time, allowing yo
|
|
|
65
65
|
|
|
66
66
|
---
|
|
67
67
|
|
|
68
|
+
## **Cloud Setup**
|
|
69
|
+
The **VM Setup Tool** also supports cloud setup for VMs. Use the following example to configure and run the cloud setup:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from vm_tool.runner import SetupRunner
|
|
73
|
+
|
|
74
|
+
runner = SetupRunner(
|
|
75
|
+
github_username='your_github_username', # e.g., username
|
|
76
|
+
github_token='your_github_token', # e.g., token
|
|
77
|
+
github_project_url='your_github_project_url' # e.g., https://github.com/username/repo
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
runner.run_cloud_setup(
|
|
81
|
+
ssh_username='your_ssh_username', # e.g., ssh_user
|
|
82
|
+
ssh_password='your_ssh_password', # e.g., ssh_password
|
|
83
|
+
ssh_hostname='your_ssh_hostname' # e.g., ssh.example.com
|
|
84
|
+
)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### **What Happens During Cloud Setup**
|
|
88
|
+
When you run the cloud setup, the tool will:
|
|
89
|
+
1. Connect to the specified cloud VM using SSH.
|
|
90
|
+
2. Clone the specified GitHub repository to the VM.
|
|
91
|
+
3. Install **Docker** if it’s not already available on the VM.
|
|
92
|
+
4. Install **Docker Compose** for managing multi-container applications.
|
|
93
|
+
5. Create, enable, and start the Docker service on the VM.
|
|
94
|
+
6. Ensure the Docker container remains active, providing a robust environment for your applications.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
68
98
|
## **SSH Client Feature**
|
|
69
99
|
The **VM Setup Tool** also includes a dedicated **SSH client** feature to simplify the configuration of SSH access for VMs, including automated SSH key generation and management.
|
|
70
100
|
|
|
@@ -49,6 +49,36 @@ By automating these tasks, the tool minimizes errors and saves time, allowing yo
|
|
|
49
49
|
|
|
50
50
|
---
|
|
51
51
|
|
|
52
|
+
## **Cloud Setup**
|
|
53
|
+
The **VM Setup Tool** also supports cloud setup for VMs. Use the following example to configure and run the cloud setup:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from vm_tool.runner import SetupRunner
|
|
57
|
+
|
|
58
|
+
runner = SetupRunner(
|
|
59
|
+
github_username='your_github_username', # e.g., username
|
|
60
|
+
github_token='your_github_token', # e.g., token
|
|
61
|
+
github_project_url='your_github_project_url' # e.g., https://github.com/username/repo
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
runner.run_cloud_setup(
|
|
65
|
+
ssh_username='your_ssh_username', # e.g., ssh_user
|
|
66
|
+
ssh_password='your_ssh_password', # e.g., ssh_password
|
|
67
|
+
ssh_hostname='your_ssh_hostname' # e.g., ssh.example.com
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### **What Happens During Cloud Setup**
|
|
72
|
+
When you run the cloud setup, the tool will:
|
|
73
|
+
1. Connect to the specified cloud VM using SSH.
|
|
74
|
+
2. Clone the specified GitHub repository to the VM.
|
|
75
|
+
3. Install **Docker** if it’s not already available on the VM.
|
|
76
|
+
4. Install **Docker Compose** for managing multi-container applications.
|
|
77
|
+
5. Create, enable, and start the Docker service on the VM.
|
|
78
|
+
6. Ensure the Docker container remains active, providing a robust environment for your applications.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
52
82
|
## **SSH Client Feature**
|
|
53
83
|
The **VM Setup Tool** also includes a dedicated **SSH client** feature to simplify the configuration of SSH access for VMs, including automated SSH key generation and management.
|
|
54
84
|
|
|
@@ -78,4 +108,4 @@ When you run the SSH setup, the tool will:
|
|
|
78
108
|
|
|
79
109
|
---
|
|
80
110
|
|
|
81
|
-
With its comprehensive features, the **VM Setup Tool** eliminates the hassle of manual configurations and enables seamless integration of VMs into your workflows. Start using the tool today to automate and optimize your virtual machine setup process.
|
|
111
|
+
With its comprehensive features, the **VM Setup Tool** eliminates the hassle of manual configurations and enables seamless integration of VMs into your workflows. Start using the tool today to automate and optimize your virtual machine setup process.
|
|
@@ -11,7 +11,7 @@ else:
|
|
|
11
11
|
|
|
12
12
|
setup(
|
|
13
13
|
name='vm_tool',
|
|
14
|
-
version='1.0.
|
|
14
|
+
version='1.0.14', # This will be updated by bump2version
|
|
15
15
|
packages=find_packages(),
|
|
16
16
|
description='A Comprehensive Tool for Setting Up Virtual Machines Using Ansible.',
|
|
17
17
|
long_description=long_description,
|
|
@@ -2,7 +2,7 @@ import argparse
|
|
|
2
2
|
|
|
3
3
|
def main():
|
|
4
4
|
parser = argparse.ArgumentParser(description='Setup VMs using Ansible.')
|
|
5
|
-
parser.add_argument('--version', action='version', version='1.0.
|
|
5
|
+
parser.add_argument('--version', action='version', version='1.0.14')
|
|
6
6
|
|
|
7
7
|
args = parser.parse_args()
|
|
8
8
|
|
|
@@ -30,6 +30,48 @@ class SetupRunner:
|
|
|
30
30
|
playbook_path = os.path.join(current_dir, 'vm_setup', 'setup.yml')
|
|
31
31
|
inventory_path = os.path.join(current_dir, 'vm_setup', 'inventory.yml')
|
|
32
32
|
|
|
33
|
+
try:
|
|
34
|
+
# Run the Ansible playbook using ansible-runner
|
|
35
|
+
r = ansible_runner.run(
|
|
36
|
+
private_data_dir=venv_dir,
|
|
37
|
+
playbook=playbook_path,
|
|
38
|
+
inventory=inventory_path,
|
|
39
|
+
extravars=extravars
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
if r.rc != 0:
|
|
43
|
+
raise RuntimeError(f"Ansible playbook execution failed with return code {r.rc}: {r.stdout}")
|
|
44
|
+
|
|
45
|
+
except Exception as e:
|
|
46
|
+
raise RuntimeError(f"An error occurred while running the Ansible playbook: {str(e)}")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def run_cloud_setup(self,ssh_username,ssh_password,ssh_hostname):
|
|
50
|
+
# Construct extravars dictionary
|
|
51
|
+
extravars = {
|
|
52
|
+
'SSH_USERNAME': ssh_username,
|
|
53
|
+
'SSH_PASSWORD': ssh_password,
|
|
54
|
+
'SSH_HOSTNAME': ssh_hostname,
|
|
55
|
+
'GITHUB_USERNAME': self.github_username,
|
|
56
|
+
'GITHUB_TOKEN': self.github_token,
|
|
57
|
+
'GITHUB_PROJECT_URL': self.github_project_url
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# Get the current directory of this script
|
|
62
|
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
63
|
+
|
|
64
|
+
# Get the virtual environment directory
|
|
65
|
+
venv_dir = os.path.join(sys.prefix, 'ansible_runner_data')
|
|
66
|
+
|
|
67
|
+
# Ensure the directory exists
|
|
68
|
+
os.makedirs(venv_dir, exist_ok=True)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# Construct dynamic paths
|
|
72
|
+
playbook_path = os.path.join(current_dir, 'vm_setup', 'setup.yml')
|
|
73
|
+
inventory_path = os.path.join(current_dir, 'vm_setup', 'cloud_inventory.yml')
|
|
74
|
+
|
|
33
75
|
try:
|
|
34
76
|
# Run the Ansible playbook using ansible-runner
|
|
35
77
|
r = ansible_runner.run(
|
|
@@ -32,7 +32,7 @@ class SSHSetup:
|
|
|
32
32
|
self.client = paramiko.SSHClient()
|
|
33
33
|
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
34
34
|
|
|
35
|
-
def
|
|
35
|
+
def __generate_ssh_key(self, email):
|
|
36
36
|
"""
|
|
37
37
|
Generates an SSH key pair.
|
|
38
38
|
|
|
@@ -42,7 +42,7 @@ class SSHSetup:
|
|
|
42
42
|
print(f"Generating SSH key for email: {email}")
|
|
43
43
|
os.system(f'ssh-keygen -t rsa -b 4096 -C "{email}"')
|
|
44
44
|
|
|
45
|
-
def
|
|
45
|
+
def __read_or_generate_public_key(self, email):
|
|
46
46
|
"""
|
|
47
47
|
Reads the public SSH key or generates a new one if it doesn't exist.
|
|
48
48
|
|
|
@@ -54,12 +54,12 @@ class SSHSetup:
|
|
|
54
54
|
"""
|
|
55
55
|
public_key_path = f'{self.private_key_path}.pub'
|
|
56
56
|
if not os.path.exists(public_key_path):
|
|
57
|
-
self.
|
|
57
|
+
self.__generate_ssh_key(email)
|
|
58
58
|
with open(public_key_path, 'r') as file:
|
|
59
59
|
print(f"Reading public key from {public_key_path}")
|
|
60
60
|
return file.read()
|
|
61
61
|
|
|
62
|
-
def
|
|
62
|
+
def __configure_vm(self, vm_ip, vm_password, public_key):
|
|
63
63
|
"""
|
|
64
64
|
Configures the VM by adding the public SSH key to the authorized keys.
|
|
65
65
|
|
|
@@ -73,7 +73,7 @@ class SSHSetup:
|
|
|
73
73
|
self.client.exec_command(f'echo "{public_key}" >> ~/.ssh/authorized_keys')
|
|
74
74
|
self.client.close()
|
|
75
75
|
|
|
76
|
-
def
|
|
76
|
+
def __update_ssh_config(self):
|
|
77
77
|
"""
|
|
78
78
|
Updates the local SSH config file with the VM details.
|
|
79
79
|
"""
|
|
@@ -89,14 +89,14 @@ Host {self.hostname}
|
|
|
89
89
|
with open(f'{os.path.expanduser("~")}/.ssh/config', 'a') as file:
|
|
90
90
|
file.write(config)
|
|
91
91
|
|
|
92
|
-
def
|
|
92
|
+
def __establish_connection(self):
|
|
93
93
|
"""
|
|
94
94
|
Establishes an SSH connection to the VM.
|
|
95
95
|
"""
|
|
96
96
|
print(f"Establishing SSH connection to {self.hostname}.")
|
|
97
97
|
self.client.connect(self.hostname, username=self.username, key_filename=self.private_key_path)
|
|
98
98
|
|
|
99
|
-
def
|
|
99
|
+
def __close_connection(self):
|
|
100
100
|
"""
|
|
101
101
|
Closes the SSH connection.
|
|
102
102
|
"""
|
|
@@ -109,9 +109,9 @@ Host {self.hostname}
|
|
|
109
109
|
Sets up the SSH configuration and keys for the VM.
|
|
110
110
|
"""
|
|
111
111
|
print("Starting SSH setup.")
|
|
112
|
-
public_key = self.
|
|
113
|
-
self.
|
|
114
|
-
self.
|
|
115
|
-
self.
|
|
116
|
-
self.
|
|
112
|
+
public_key = self.__read_or_generate_public_key(self.email)
|
|
113
|
+
self.__configure_vm(self.hostname, self.password, public_key)
|
|
114
|
+
self.__update_ssh_config()
|
|
115
|
+
self.__establish_connection()
|
|
116
|
+
self.__close_connection()
|
|
117
117
|
print("SSH setup completed.")
|
|
@@ -3,24 +3,17 @@
|
|
|
3
3
|
gather_facts: yes
|
|
4
4
|
|
|
5
5
|
vars:
|
|
6
|
-
github_project_url: "{{ lookup('env', 'GITHUB_PROJECT_URL') }}"
|
|
7
|
-
github_username: "{{ lookup('env', 'GITHUB_USERNAME') }}"
|
|
8
|
-
github_token: "{{ lookup('env', 'GITHUB_TOKEN') }}"
|
|
9
6
|
static_playbook_dir: "{{ playbook_dir }}"
|
|
10
7
|
|
|
11
8
|
tasks:
|
|
12
9
|
- name: Set project_dest_dir variable
|
|
13
10
|
set_fact:
|
|
14
11
|
project_dest_dir: "{{ static_playbook_dir }}/project"
|
|
15
|
-
|
|
16
|
-
- name: Set project_repo_url variable
|
|
17
|
-
set_fact:
|
|
18
|
-
project_repo_url: "{{ github_project_url }}"
|
|
19
12
|
|
|
20
13
|
- name: Configure Git with GitHub token
|
|
21
14
|
shell: |
|
|
22
15
|
git config --global credential.helper store
|
|
23
|
-
echo "https://{{
|
|
16
|
+
echo "https://{{ GITHUB_USERNAME }}:{{ GITHUB_TOKEN }}@github.com" > ~/.git-credentials
|
|
24
17
|
become: yes
|
|
25
18
|
|
|
26
19
|
- name: Remove existing Project repository if present
|
|
@@ -32,7 +25,7 @@
|
|
|
32
25
|
|
|
33
26
|
- name: Clone the Project repository
|
|
34
27
|
git:
|
|
35
|
-
repo: "{{
|
|
28
|
+
repo: "{{ GITHUB_PROJECT_URL }}"
|
|
36
29
|
dest: "{{ project_dest_dir }}"
|
|
37
30
|
version: main
|
|
38
31
|
become: yes
|
|
@@ -72,6 +65,6 @@
|
|
|
72
65
|
unset GITHUB_USERNAME
|
|
73
66
|
unset GITHUB_TOKEN
|
|
74
67
|
environment:
|
|
75
|
-
GITHUB_PROJECT_URL: "{{
|
|
76
|
-
GITHUB_USERNAME: "{{
|
|
77
|
-
GITHUB_TOKEN: "{{
|
|
68
|
+
GITHUB_PROJECT_URL: "{{ GITHUB_PROJECT_URL }}"
|
|
69
|
+
GITHUB_USERNAME: "{{ GITHUB_USERNAME }}"
|
|
70
|
+
GITHUB_TOKEN: "{{ GITHUB_TOKEN }}"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: vm_tool
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.14
|
|
4
4
|
Summary: A Comprehensive Tool for Setting Up Virtual Machines Using Ansible.
|
|
5
5
|
License: MIT
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -65,6 +65,36 @@ By automating these tasks, the tool minimizes errors and saves time, allowing yo
|
|
|
65
65
|
|
|
66
66
|
---
|
|
67
67
|
|
|
68
|
+
## **Cloud Setup**
|
|
69
|
+
The **VM Setup Tool** also supports cloud setup for VMs. Use the following example to configure and run the cloud setup:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from vm_tool.runner import SetupRunner
|
|
73
|
+
|
|
74
|
+
runner = SetupRunner(
|
|
75
|
+
github_username='your_github_username', # e.g., username
|
|
76
|
+
github_token='your_github_token', # e.g., token
|
|
77
|
+
github_project_url='your_github_project_url' # e.g., https://github.com/username/repo
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
runner.run_cloud_setup(
|
|
81
|
+
ssh_username='your_ssh_username', # e.g., ssh_user
|
|
82
|
+
ssh_password='your_ssh_password', # e.g., ssh_password
|
|
83
|
+
ssh_hostname='your_ssh_hostname' # e.g., ssh.example.com
|
|
84
|
+
)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### **What Happens During Cloud Setup**
|
|
88
|
+
When you run the cloud setup, the tool will:
|
|
89
|
+
1. Connect to the specified cloud VM using SSH.
|
|
90
|
+
2. Clone the specified GitHub repository to the VM.
|
|
91
|
+
3. Install **Docker** if it’s not already available on the VM.
|
|
92
|
+
4. Install **Docker Compose** for managing multi-container applications.
|
|
93
|
+
5. Create, enable, and start the Docker service on the VM.
|
|
94
|
+
6. Ensure the Docker container remains active, providing a robust environment for your applications.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
68
98
|
## **SSH Client Feature**
|
|
69
99
|
The **VM Setup Tool** also includes a dedicated **SSH client** feature to simplify the configuration of SSH access for VMs, including automated SSH key generation and management.
|
|
70
100
|
|
|
@@ -12,6 +12,7 @@ vm_tool.egg-info/dependency_links.txt
|
|
|
12
12
|
vm_tool.egg-info/entry_points.txt
|
|
13
13
|
vm_tool.egg-info/requires.txt
|
|
14
14
|
vm_tool.egg-info/top_level.txt
|
|
15
|
+
vm_tool/vm_setup/cloud_inventory.yml
|
|
15
16
|
vm_tool/vm_setup/inventory.yml
|
|
16
17
|
vm_tool/vm_setup/setup.yml
|
|
17
18
|
vm_tool/vm_setup/docker/create_docker_service.yml
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|