vm-tool 1.0.20__tar.gz → 1.0.22__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.20/vm_tool.egg-info → vm_tool-1.0.22}/PKG-INFO +25 -17
- {vm_tool-1.0.20 → vm_tool-1.0.22}/README.md +24 -16
- {vm_tool-1.0.20 → vm_tool-1.0.22}/setup.py +1 -1
- {vm_tool-1.0.20 → vm_tool-1.0.22}/vm_tool/cli.py +1 -1
- {vm_tool-1.0.20 → vm_tool-1.0.22}/vm_tool/runner.py +36 -6
- vm_tool-1.0.22/vm_tool/vm_setup/cleanup.yml +27 -0
- vm_tool-1.0.22/vm_tool/vm_setup/docker/docker_setup.yml +7 -0
- vm_tool-1.0.22/vm_tool/vm_setup/docker/login_to_docker_hub.yml +6 -0
- vm_tool-1.0.22/vm_tool/vm_setup/dynamic_inventory.yml +8 -0
- vm_tool-1.0.22/vm_tool/vm_setup/github/git_configuration.yml +22 -0
- vm_tool-1.0.22/vm_tool/vm_setup/main.yml +19 -0
- vm_tool-1.0.22/vm_tool/vm_setup/project_service.yml +16 -0
- vm_tool-1.0.22/vm_tool/vm_setup/setup.yml +11 -0
- {vm_tool-1.0.20 → vm_tool-1.0.22/vm_tool.egg-info}/PKG-INFO +25 -17
- {vm_tool-1.0.20 → vm_tool-1.0.22}/vm_tool.egg-info/SOURCES.txt +7 -1
- vm_tool-1.0.20/vm_tool/vm_setup/dynamic_inventory.yml +0 -0
- vm_tool-1.0.20/vm_tool/vm_setup/setup.yml +0 -81
- {vm_tool-1.0.20 → vm_tool-1.0.22}/LICENSE +0 -0
- {vm_tool-1.0.20 → vm_tool-1.0.22}/MANIFEST.in +0 -0
- {vm_tool-1.0.20 → vm_tool-1.0.22}/setup.cfg +0 -0
- {vm_tool-1.0.20 → vm_tool-1.0.22}/vm_tool/__init__.py +0 -0
- {vm_tool-1.0.20 → vm_tool-1.0.22}/vm_tool/ssh.py +0 -0
- {vm_tool-1.0.20 → vm_tool-1.0.22}/vm_tool/vm_setup/docker/create_docker_service.yml +0 -0
- {vm_tool-1.0.20 → vm_tool-1.0.22}/vm_tool/vm_setup/docker/install_docker_and_compose.yml +0 -0
- {vm_tool-1.0.20 → vm_tool-1.0.22}/vm_tool/vm_setup/inventory.yml +0 -0
- {vm_tool-1.0.20 → vm_tool-1.0.22}/vm_tool.egg-info/dependency_links.txt +0 -0
- {vm_tool-1.0.20 → vm_tool-1.0.22}/vm_tool.egg-info/entry_points.txt +0 -0
- {vm_tool-1.0.20 → vm_tool-1.0.22}/vm_tool.egg-info/requires.txt +0 -0
- {vm_tool-1.0.20 → vm_tool-1.0.22}/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.22
|
|
4
4
|
Summary: A Comprehensive Tool for Setting Up Virtual Machines.
|
|
5
5
|
Home-page: https://github.com/thesunnysinha/vm_tool
|
|
6
6
|
Author: Sunny Sinha
|
|
@@ -83,10 +83,12 @@ Use the following example to configure and run the VM setup:
|
|
|
83
83
|
from vm_tool.runner import SetupRunner, SetupRunnerConfig
|
|
84
84
|
|
|
85
85
|
config = SetupRunnerConfig(
|
|
86
|
-
github_username='your_github_username', # e.g., username
|
|
87
|
-
github_token='your_github_token', # e.g., token
|
|
86
|
+
github_username='your_github_username', # Required if the repository is private, e.g., username
|
|
87
|
+
github_token='your_github_token', # Required if the repository is private, e.g., token
|
|
88
88
|
github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
|
|
89
|
-
docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
|
|
89
|
+
docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
|
|
90
|
+
dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
|
|
91
|
+
dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
|
|
90
92
|
)
|
|
91
93
|
|
|
92
94
|
runner = SetupRunner(config)
|
|
@@ -96,11 +98,13 @@ runner.run_setup()
|
|
|
96
98
|
|
|
97
99
|
### **What Happens During Setup**
|
|
98
100
|
The VM Setup Tool will:
|
|
99
|
-
1.
|
|
100
|
-
2.
|
|
101
|
-
3. Install **Docker
|
|
102
|
-
4.
|
|
103
|
-
5.
|
|
101
|
+
1. Configure Git with GitHub token if provided.
|
|
102
|
+
2. Clone the specified GitHub repository to your local machine.
|
|
103
|
+
3. Install **Docker** if it’s not already available on the target machine.
|
|
104
|
+
4. Install **Docker Compose** for managing multi-container applications.
|
|
105
|
+
5. Log in to Docker Hub if credentials are provided.
|
|
106
|
+
6. Create, enable, and start the Docker service.
|
|
107
|
+
7. Ensure the Docker container remains active, providing a robust environment for your applications.
|
|
104
108
|
|
|
105
109
|
By automating these tasks, the tool minimizes errors and saves time, allowing you to focus on development and deployment.
|
|
106
110
|
|
|
@@ -113,10 +117,12 @@ The **VM Setup Tool** also supports cloud setup for VMs. Use the following examp
|
|
|
113
117
|
from vm_tool.runner import SetupRunner, SetupRunnerConfig, SSHConfig
|
|
114
118
|
|
|
115
119
|
config = SetupRunnerConfig(
|
|
116
|
-
github_username='your_github_username', # e.g., username
|
|
117
|
-
github_token='your_github_token', # e.g., token
|
|
120
|
+
github_username='your_github_username', # Required if the repository is private, e.g., username
|
|
121
|
+
github_token='your_github_token', # Required if the repository is private, e.g., token
|
|
118
122
|
github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
|
|
119
|
-
docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
|
|
123
|
+
docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
|
|
124
|
+
dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
|
|
125
|
+
dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
|
|
120
126
|
)
|
|
121
127
|
|
|
122
128
|
runner = SetupRunner(config)
|
|
@@ -141,11 +147,13 @@ runner.run_cloud_setup(ssh_configs)
|
|
|
141
147
|
### **What Happens During Cloud Setup**
|
|
142
148
|
When you run the cloud setup, the tool will:
|
|
143
149
|
1. Connect to the specified cloud VM using SSH.
|
|
144
|
-
2.
|
|
145
|
-
3.
|
|
146
|
-
4. Install **Docker
|
|
147
|
-
5.
|
|
148
|
-
6.
|
|
150
|
+
2. Configure Git with GitHub token if provided.
|
|
151
|
+
3. Clone the specified GitHub repository to the VM.
|
|
152
|
+
4. Install **Docker** if it’s not already available on the VM.
|
|
153
|
+
5. Install **Docker Compose** for managing multi-container applications.
|
|
154
|
+
6. Log in to Docker Hub if credentials are provided.
|
|
155
|
+
7. Create, enable, and start the Docker service on the VM.
|
|
156
|
+
8. Ensure the Docker container remains active, providing a robust environment for your applications.
|
|
149
157
|
|
|
150
158
|
---
|
|
151
159
|
|
|
@@ -29,10 +29,12 @@ Use the following example to configure and run the VM setup:
|
|
|
29
29
|
from vm_tool.runner import SetupRunner, SetupRunnerConfig
|
|
30
30
|
|
|
31
31
|
config = SetupRunnerConfig(
|
|
32
|
-
github_username='your_github_username', # e.g., username
|
|
33
|
-
github_token='your_github_token', # e.g., token
|
|
32
|
+
github_username='your_github_username', # Required if the repository is private, e.g., username
|
|
33
|
+
github_token='your_github_token', # Required if the repository is private, e.g., token
|
|
34
34
|
github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
|
|
35
|
-
docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
|
|
35
|
+
docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
|
|
36
|
+
dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
|
|
37
|
+
dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
|
|
36
38
|
)
|
|
37
39
|
|
|
38
40
|
runner = SetupRunner(config)
|
|
@@ -42,11 +44,13 @@ runner.run_setup()
|
|
|
42
44
|
|
|
43
45
|
### **What Happens During Setup**
|
|
44
46
|
The VM Setup Tool will:
|
|
45
|
-
1.
|
|
46
|
-
2.
|
|
47
|
-
3. Install **Docker
|
|
48
|
-
4.
|
|
49
|
-
5.
|
|
47
|
+
1. Configure Git with GitHub token if provided.
|
|
48
|
+
2. Clone the specified GitHub repository to your local machine.
|
|
49
|
+
3. Install **Docker** if it’s not already available on the target machine.
|
|
50
|
+
4. Install **Docker Compose** for managing multi-container applications.
|
|
51
|
+
5. Log in to Docker Hub if credentials are provided.
|
|
52
|
+
6. Create, enable, and start the Docker service.
|
|
53
|
+
7. Ensure the Docker container remains active, providing a robust environment for your applications.
|
|
50
54
|
|
|
51
55
|
By automating these tasks, the tool minimizes errors and saves time, allowing you to focus on development and deployment.
|
|
52
56
|
|
|
@@ -59,10 +63,12 @@ The **VM Setup Tool** also supports cloud setup for VMs. Use the following examp
|
|
|
59
63
|
from vm_tool.runner import SetupRunner, SetupRunnerConfig, SSHConfig
|
|
60
64
|
|
|
61
65
|
config = SetupRunnerConfig(
|
|
62
|
-
github_username='your_github_username', # e.g., username
|
|
63
|
-
github_token='your_github_token', # e.g., token
|
|
66
|
+
github_username='your_github_username', # Required if the repository is private, e.g., username
|
|
67
|
+
github_token='your_github_token', # Required if the repository is private, e.g., token
|
|
64
68
|
github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
|
|
65
|
-
docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
|
|
69
|
+
docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
|
|
70
|
+
dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
|
|
71
|
+
dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
|
|
66
72
|
)
|
|
67
73
|
|
|
68
74
|
runner = SetupRunner(config)
|
|
@@ -87,11 +93,13 @@ runner.run_cloud_setup(ssh_configs)
|
|
|
87
93
|
### **What Happens During Cloud Setup**
|
|
88
94
|
When you run the cloud setup, the tool will:
|
|
89
95
|
1. Connect to the specified cloud VM using SSH.
|
|
90
|
-
2.
|
|
91
|
-
3.
|
|
92
|
-
4. Install **Docker
|
|
93
|
-
5.
|
|
94
|
-
6.
|
|
96
|
+
2. Configure Git with GitHub token if provided.
|
|
97
|
+
3. Clone the specified GitHub repository to the VM.
|
|
98
|
+
4. Install **Docker** if it’s not already available on the VM.
|
|
99
|
+
5. Install **Docker Compose** for managing multi-container applications.
|
|
100
|
+
6. Log in to Docker Hub if credentials are provided.
|
|
101
|
+
7. Create, enable, and start the Docker service on the VM.
|
|
102
|
+
8. Ensure the Docker container remains active, providing a robust environment for your applications.
|
|
95
103
|
|
|
96
104
|
---
|
|
97
105
|
|
|
@@ -11,7 +11,7 @@ else:
|
|
|
11
11
|
|
|
12
12
|
setup(
|
|
13
13
|
name='vm_tool',
|
|
14
|
-
version='1.0.
|
|
14
|
+
version='1.0.22', # This will be updated by bump2version
|
|
15
15
|
packages=find_packages(),
|
|
16
16
|
description='A Comprehensive Tool for Setting Up Virtual Machines.',
|
|
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.22')
|
|
6
6
|
|
|
7
7
|
args = parser.parse_args()
|
|
8
8
|
|
|
@@ -3,18 +3,44 @@ import ansible_runner
|
|
|
3
3
|
import os
|
|
4
4
|
import yaml
|
|
5
5
|
from pydantic import BaseModel, validator
|
|
6
|
-
from typing import List
|
|
6
|
+
from typing import List, Optional
|
|
7
7
|
|
|
8
8
|
class SetupRunnerConfig(BaseModel):
|
|
9
|
-
github_username: str
|
|
10
|
-
github_token: str
|
|
9
|
+
github_username: Optional[str] = None
|
|
10
|
+
github_token: Optional[str] = None
|
|
11
11
|
github_project_url: str
|
|
12
12
|
docker_compose_file_path: str = 'docker-compose.yml'
|
|
13
|
+
dockerhub_username: Optional[str] = None
|
|
14
|
+
dockerhub_password: Optional[str] = None
|
|
13
15
|
|
|
14
16
|
@validator('docker_compose_file_path', pre=True, always=True)
|
|
15
17
|
def set_default_docker_compose_file_path(cls, v):
|
|
16
18
|
return v or 'docker-compose.yml'
|
|
17
19
|
|
|
20
|
+
@validator('dockerhub_password', always=True)
|
|
21
|
+
def check_dockerhub_password(cls, v, values):
|
|
22
|
+
if values.get('dockerhub_username') and not v:
|
|
23
|
+
raise ValueError("DockerHub password must be provided if DockerHub username is specified")
|
|
24
|
+
return v
|
|
25
|
+
|
|
26
|
+
@validator('dockerhub_username', always=True)
|
|
27
|
+
def check_dockerhub_username(cls, v, values):
|
|
28
|
+
if values.get('dockerhub_password') and not v:
|
|
29
|
+
raise ValueError("DockerHub username must be provided if DockerHub password is specified")
|
|
30
|
+
return v
|
|
31
|
+
|
|
32
|
+
@validator('github_token', always=True)
|
|
33
|
+
def check_github_token(cls, v, values):
|
|
34
|
+
if values.get('github_username') and not v:
|
|
35
|
+
raise ValueError("GitHub token must be provided if GitHub username is specified")
|
|
36
|
+
return v
|
|
37
|
+
|
|
38
|
+
@validator('github_username', always=True)
|
|
39
|
+
def check_github_username(cls, v, values):
|
|
40
|
+
if values.get('github_token') and not v:
|
|
41
|
+
raise ValueError("GitHub username must be provided if GitHub token is specified")
|
|
42
|
+
return v
|
|
43
|
+
|
|
18
44
|
class SSHConfig(BaseModel):
|
|
19
45
|
ssh_username: str
|
|
20
46
|
ssh_password: str
|
|
@@ -26,6 +52,8 @@ class SetupRunner:
|
|
|
26
52
|
self.github_token = config.github_token
|
|
27
53
|
self.github_project_url = config.github_project_url
|
|
28
54
|
self.docker_compose_file_path = config.docker_compose_file_path
|
|
55
|
+
self.dockerhub_username = config.dockerhub_username
|
|
56
|
+
self.dockerhub_password = config.dockerhub_password
|
|
29
57
|
|
|
30
58
|
def _run_ansible_playbook(self, extravars, inventory_file):
|
|
31
59
|
# Get the current directory of this script
|
|
@@ -38,7 +66,7 @@ class SetupRunner:
|
|
|
38
66
|
os.makedirs(venv_dir, exist_ok=True)
|
|
39
67
|
|
|
40
68
|
# Construct dynamic paths
|
|
41
|
-
playbook_path = os.path.join(current_dir, 'vm_setup', '
|
|
69
|
+
playbook_path = os.path.join(current_dir, 'vm_setup', 'main.yml')
|
|
42
70
|
inventory_path = os.path.join(current_dir, 'vm_setup', inventory_file)
|
|
43
71
|
|
|
44
72
|
try:
|
|
@@ -62,6 +90,8 @@ class SetupRunner:
|
|
|
62
90
|
'GITHUB_USERNAME': self.github_username,
|
|
63
91
|
'GITHUB_TOKEN': self.github_token,
|
|
64
92
|
'GITHUB_PROJECT_URL': self.github_project_url,
|
|
93
|
+
'DOCKERHUB_USERNAME': self.dockerhub_username,
|
|
94
|
+
'DOCKERHUB_PASSWORD': self.dockerhub_password,
|
|
65
95
|
'EXECUTION_TYPE': "normal"
|
|
66
96
|
}
|
|
67
97
|
|
|
@@ -84,8 +114,6 @@ class SetupRunner:
|
|
|
84
114
|
}
|
|
85
115
|
}
|
|
86
116
|
|
|
87
|
-
print(ssh_configs)
|
|
88
|
-
|
|
89
117
|
for i, ssh_config in enumerate(ssh_configs):
|
|
90
118
|
host_key = f'cloud_host_{i}'
|
|
91
119
|
inventory_content['all']['hosts'][host_key] = {
|
|
@@ -103,6 +131,8 @@ class SetupRunner:
|
|
|
103
131
|
'GITHUB_USERNAME': self.github_username,
|
|
104
132
|
'GITHUB_TOKEN': self.github_token,
|
|
105
133
|
'GITHUB_PROJECT_URL': self.github_project_url,
|
|
134
|
+
'DOCKERHUB_USERNAME': self.dockerhub_username,
|
|
135
|
+
'DOCKERHUB_PASSWORD': self.dockerhub_password,
|
|
106
136
|
'EXECUTION_TYPE': "cloud"
|
|
107
137
|
}
|
|
108
138
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
- name: Cleanup VM
|
|
2
|
+
block:
|
|
3
|
+
- name: Remove GitHub credentials from git-credentials
|
|
4
|
+
file:
|
|
5
|
+
path: ~/.git-credentials
|
|
6
|
+
state: absent
|
|
7
|
+
become: yes
|
|
8
|
+
when: GITHUB_TOKEN is defined
|
|
9
|
+
|
|
10
|
+
- name: Clear Git credential helper configuration
|
|
11
|
+
shell: git config --global --unset credential.helper
|
|
12
|
+
become: yes
|
|
13
|
+
when: GITHUB_TOKEN is defined
|
|
14
|
+
|
|
15
|
+
- name: Unset environment variables
|
|
16
|
+
shell: |
|
|
17
|
+
unset GITHUB_PROJECT_URL
|
|
18
|
+
unset GITHUB_USERNAME
|
|
19
|
+
unset GITHUB_TOKEN
|
|
20
|
+
unset DOCKERHUB_USERNAME
|
|
21
|
+
unset DOCKERHUB_PASSWORD
|
|
22
|
+
environment:
|
|
23
|
+
GITHUB_PROJECT_URL: "{{ GITHUB_PROJECT_URL }}"
|
|
24
|
+
GITHUB_USERNAME: "{{ GITHUB_USERNAME }}"
|
|
25
|
+
GITHUB_TOKEN: "{{ GITHUB_TOKEN }}"
|
|
26
|
+
DOCKERHUB_USERNAME: "{{ DOCKERHUB_USERNAME }}"
|
|
27
|
+
DOCKERHUB_PASSWORD: "{{ DOCKERHUB_PASSWORD }}"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
- name: Git Configuration Playbook
|
|
2
|
+
block:
|
|
3
|
+
- name: Configure Git with GitHub token
|
|
4
|
+
shell: |
|
|
5
|
+
git config --global credential.helper store
|
|
6
|
+
echo "https://{{ GITHUB_USERNAME }}:{{ GITHUB_TOKEN }}@github.com" > ~/.git-credentials
|
|
7
|
+
become: yes
|
|
8
|
+
when: GITHUB_TOKEN is defined and GITHUB_USERNAME is defined
|
|
9
|
+
|
|
10
|
+
- name: Remove existing Project repository if present
|
|
11
|
+
file:
|
|
12
|
+
path: "{{ project_dest_dir }}"
|
|
13
|
+
state: absent
|
|
14
|
+
force: yes
|
|
15
|
+
become: yes
|
|
16
|
+
|
|
17
|
+
- name: Clone the Project repository
|
|
18
|
+
git:
|
|
19
|
+
repo: "{{ GITHUB_PROJECT_URL }}"
|
|
20
|
+
dest: "{{ project_dest_dir }}"
|
|
21
|
+
version: main
|
|
22
|
+
become: yes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
- name: Main Playbook
|
|
2
|
+
hosts: all
|
|
3
|
+
gather_facts: yes
|
|
4
|
+
|
|
5
|
+
tasks:
|
|
6
|
+
- name: Setup
|
|
7
|
+
include_tasks: setup.yml
|
|
8
|
+
|
|
9
|
+
- name: Git Configuration
|
|
10
|
+
include_tasks: github/git_configuration.yml
|
|
11
|
+
|
|
12
|
+
- name: Docker Setup
|
|
13
|
+
include_tasks: docker/docker_setup.yml
|
|
14
|
+
|
|
15
|
+
- name: Project Service
|
|
16
|
+
include_tasks: project_service.yml
|
|
17
|
+
|
|
18
|
+
- name: Cleanup
|
|
19
|
+
include_tasks: cleanup.yml
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
- name: Project Service Playbook
|
|
2
|
+
block:
|
|
3
|
+
- name: Set service_file_path variable
|
|
4
|
+
set_fact:
|
|
5
|
+
service_file_path: /etc/systemd/system/project.service
|
|
6
|
+
|
|
7
|
+
- name: Create Docker Service
|
|
8
|
+
include_tasks: docker/create_docker_service.yml
|
|
9
|
+
|
|
10
|
+
- name: Enable and start project service
|
|
11
|
+
ansible.builtin.systemd:
|
|
12
|
+
name: project
|
|
13
|
+
state: started
|
|
14
|
+
enabled: yes
|
|
15
|
+
become: yes
|
|
16
|
+
ignore_errors: yes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
- name: Setup VM
|
|
2
|
+
block:
|
|
3
|
+
- name: Set project_dest_dir variable for cloud
|
|
4
|
+
set_fact:
|
|
5
|
+
project_dest_dir: "{{ ansible_user_dir }}/project"
|
|
6
|
+
when: EXECUTION_TYPE == "cloud"
|
|
7
|
+
|
|
8
|
+
- name: Set project_dest_dir variable for normal
|
|
9
|
+
set_fact:
|
|
10
|
+
project_dest_dir: "{{ playbook_dir }}/project"
|
|
11
|
+
when: EXECUTION_TYPE == "normal"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: vm_tool
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.22
|
|
4
4
|
Summary: A Comprehensive Tool for Setting Up Virtual Machines.
|
|
5
5
|
Home-page: https://github.com/thesunnysinha/vm_tool
|
|
6
6
|
Author: Sunny Sinha
|
|
@@ -83,10 +83,12 @@ Use the following example to configure and run the VM setup:
|
|
|
83
83
|
from vm_tool.runner import SetupRunner, SetupRunnerConfig
|
|
84
84
|
|
|
85
85
|
config = SetupRunnerConfig(
|
|
86
|
-
github_username='your_github_username', # e.g., username
|
|
87
|
-
github_token='your_github_token', # e.g., token
|
|
86
|
+
github_username='your_github_username', # Required if the repository is private, e.g., username
|
|
87
|
+
github_token='your_github_token', # Required if the repository is private, e.g., token
|
|
88
88
|
github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
|
|
89
|
-
docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
|
|
89
|
+
docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
|
|
90
|
+
dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
|
|
91
|
+
dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
|
|
90
92
|
)
|
|
91
93
|
|
|
92
94
|
runner = SetupRunner(config)
|
|
@@ -96,11 +98,13 @@ runner.run_setup()
|
|
|
96
98
|
|
|
97
99
|
### **What Happens During Setup**
|
|
98
100
|
The VM Setup Tool will:
|
|
99
|
-
1.
|
|
100
|
-
2.
|
|
101
|
-
3. Install **Docker
|
|
102
|
-
4.
|
|
103
|
-
5.
|
|
101
|
+
1. Configure Git with GitHub token if provided.
|
|
102
|
+
2. Clone the specified GitHub repository to your local machine.
|
|
103
|
+
3. Install **Docker** if it’s not already available on the target machine.
|
|
104
|
+
4. Install **Docker Compose** for managing multi-container applications.
|
|
105
|
+
5. Log in to Docker Hub if credentials are provided.
|
|
106
|
+
6. Create, enable, and start the Docker service.
|
|
107
|
+
7. Ensure the Docker container remains active, providing a robust environment for your applications.
|
|
104
108
|
|
|
105
109
|
By automating these tasks, the tool minimizes errors and saves time, allowing you to focus on development and deployment.
|
|
106
110
|
|
|
@@ -113,10 +117,12 @@ The **VM Setup Tool** also supports cloud setup for VMs. Use the following examp
|
|
|
113
117
|
from vm_tool.runner import SetupRunner, SetupRunnerConfig, SSHConfig
|
|
114
118
|
|
|
115
119
|
config = SetupRunnerConfig(
|
|
116
|
-
github_username='your_github_username', # e.g., username
|
|
117
|
-
github_token='your_github_token', # e.g., token
|
|
120
|
+
github_username='your_github_username', # Required if the repository is private, e.g., username
|
|
121
|
+
github_token='your_github_token', # Required if the repository is private, e.g., token
|
|
118
122
|
github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
|
|
119
|
-
docker_compose_file_path='path_to_your_docker_compose_file' # Optional, defaults to 'docker-compose.yml'
|
|
123
|
+
docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
|
|
124
|
+
dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
|
|
125
|
+
dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
|
|
120
126
|
)
|
|
121
127
|
|
|
122
128
|
runner = SetupRunner(config)
|
|
@@ -141,11 +147,13 @@ runner.run_cloud_setup(ssh_configs)
|
|
|
141
147
|
### **What Happens During Cloud Setup**
|
|
142
148
|
When you run the cloud setup, the tool will:
|
|
143
149
|
1. Connect to the specified cloud VM using SSH.
|
|
144
|
-
2.
|
|
145
|
-
3.
|
|
146
|
-
4. Install **Docker
|
|
147
|
-
5.
|
|
148
|
-
6.
|
|
150
|
+
2. Configure Git with GitHub token if provided.
|
|
151
|
+
3. Clone the specified GitHub repository to the VM.
|
|
152
|
+
4. Install **Docker** if it’s not already available on the VM.
|
|
153
|
+
5. Install **Docker Compose** for managing multi-container applications.
|
|
154
|
+
6. Log in to Docker Hub if credentials are provided.
|
|
155
|
+
7. Create, enable, and start the Docker service on the VM.
|
|
156
|
+
8. Ensure the Docker container remains active, providing a robust environment for your applications.
|
|
149
157
|
|
|
150
158
|
---
|
|
151
159
|
|
|
@@ -12,8 +12,14 @@ 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/cleanup.yml
|
|
15
16
|
vm_tool/vm_setup/dynamic_inventory.yml
|
|
16
17
|
vm_tool/vm_setup/inventory.yml
|
|
18
|
+
vm_tool/vm_setup/main.yml
|
|
19
|
+
vm_tool/vm_setup/project_service.yml
|
|
17
20
|
vm_tool/vm_setup/setup.yml
|
|
18
21
|
vm_tool/vm_setup/docker/create_docker_service.yml
|
|
19
|
-
vm_tool/vm_setup/docker/
|
|
22
|
+
vm_tool/vm_setup/docker/docker_setup.yml
|
|
23
|
+
vm_tool/vm_setup/docker/install_docker_and_compose.yml
|
|
24
|
+
vm_tool/vm_setup/docker/login_to_docker_hub.yml
|
|
25
|
+
vm_tool/vm_setup/github/git_configuration.yml
|
|
File without changes
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
- name: Setup Docker and Docker Compose on Ubuntu
|
|
2
|
-
hosts: all
|
|
3
|
-
gather_facts: yes
|
|
4
|
-
|
|
5
|
-
vars:
|
|
6
|
-
static_playbook_dir: "{{ playbook_dir }}"
|
|
7
|
-
|
|
8
|
-
tasks:
|
|
9
|
-
- name: Gather package facts
|
|
10
|
-
package_facts:
|
|
11
|
-
manager: auto
|
|
12
|
-
|
|
13
|
-
- name: Install sshpass if execution type is cloud and not already installed
|
|
14
|
-
apt:
|
|
15
|
-
name: sshpass
|
|
16
|
-
state: present
|
|
17
|
-
when: EXECUTION_TYPE == "cloud" and "'sshpass' not in ansible_facts.packages"
|
|
18
|
-
become: yes
|
|
19
|
-
|
|
20
|
-
- name: Set project_dest_dir variable
|
|
21
|
-
set_fact:
|
|
22
|
-
project_dest_dir: "{{ static_playbook_dir }}/project"
|
|
23
|
-
|
|
24
|
-
- name: Configure Git with GitHub token
|
|
25
|
-
shell: |
|
|
26
|
-
git config --global credential.helper store
|
|
27
|
-
echo "https://{{ GITHUB_USERNAME }}:{{ GITHUB_TOKEN }}@github.com" > ~/.git-credentials
|
|
28
|
-
become: yes
|
|
29
|
-
|
|
30
|
-
- name: Remove existing Project repository if present
|
|
31
|
-
file:
|
|
32
|
-
path: "{{ project_dest_dir }}"
|
|
33
|
-
state: absent
|
|
34
|
-
force: yes
|
|
35
|
-
become: yes
|
|
36
|
-
|
|
37
|
-
- name: Clone the Project repository
|
|
38
|
-
git:
|
|
39
|
-
repo: "{{ GITHUB_PROJECT_URL }}"
|
|
40
|
-
dest: "{{ project_dest_dir }}"
|
|
41
|
-
version: main
|
|
42
|
-
become: yes
|
|
43
|
-
|
|
44
|
-
- name: Set service_file_path variable
|
|
45
|
-
set_fact:
|
|
46
|
-
service_file_path: /etc/systemd/system/project.service
|
|
47
|
-
|
|
48
|
-
- name: Adding Docker and Compose packages
|
|
49
|
-
include_tasks: docker/install_docker_and_compose.yml
|
|
50
|
-
|
|
51
|
-
- name: Create Docker Service
|
|
52
|
-
include_tasks: docker/create_docker_service.yml
|
|
53
|
-
|
|
54
|
-
- name: Enable and start project service
|
|
55
|
-
ansible.builtin.systemd:
|
|
56
|
-
name: project
|
|
57
|
-
state: started
|
|
58
|
-
enabled: yes
|
|
59
|
-
become: yes
|
|
60
|
-
ignore_errors: yes
|
|
61
|
-
|
|
62
|
-
# Cleanup section
|
|
63
|
-
- name: Remove GitHub credentials from git-credentials
|
|
64
|
-
file:
|
|
65
|
-
path: ~/.git-credentials
|
|
66
|
-
state: absent
|
|
67
|
-
become: yes
|
|
68
|
-
|
|
69
|
-
- name: Clear Git credential helper configuration
|
|
70
|
-
shell: git config --global --unset credential.helper
|
|
71
|
-
become: yes
|
|
72
|
-
|
|
73
|
-
- name: Unset environment variables
|
|
74
|
-
shell: |
|
|
75
|
-
unset GITHUB_PROJECT_URL
|
|
76
|
-
unset GITHUB_USERNAME
|
|
77
|
-
unset GITHUB_TOKEN
|
|
78
|
-
environment:
|
|
79
|
-
GITHUB_PROJECT_URL: "{{ GITHUB_PROJECT_URL }}"
|
|
80
|
-
GITHUB_USERNAME: "{{ GITHUB_USERNAME }}"
|
|
81
|
-
GITHUB_TOKEN: "{{ GITHUB_TOKEN }}"
|
|
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
|
|
File without changes
|