vm-tool 1.0.21__tar.gz → 1.0.24__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.
Files changed (28) hide show
  1. {vm_tool-1.0.21/vm_tool.egg-info → vm_tool-1.0.24}/PKG-INFO +9 -5
  2. {vm_tool-1.0.21 → vm_tool-1.0.24}/README.md +8 -4
  3. {vm_tool-1.0.21 → vm_tool-1.0.24}/setup.py +1 -1
  4. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/cli.py +1 -1
  5. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/runner.py +71 -19
  6. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/vm_setup/docker/install_docker_and_compose.yml +35 -13
  7. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/vm_setup/github/git_configuration.yml +20 -3
  8. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/vm_setup/main.yml +0 -3
  9. vm_tool-1.0.24/vm_tool/vm_setup/setup.yml +11 -0
  10. {vm_tool-1.0.21 → vm_tool-1.0.24/vm_tool.egg-info}/PKG-INFO +9 -5
  11. vm_tool-1.0.21/vm_tool/vm_setup/setup.yml +0 -5
  12. {vm_tool-1.0.21 → vm_tool-1.0.24}/LICENSE +0 -0
  13. {vm_tool-1.0.21 → vm_tool-1.0.24}/MANIFEST.in +0 -0
  14. {vm_tool-1.0.21 → vm_tool-1.0.24}/setup.cfg +0 -0
  15. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/__init__.py +0 -0
  16. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/ssh.py +0 -0
  17. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/vm_setup/cleanup.yml +0 -0
  18. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/vm_setup/docker/create_docker_service.yml +0 -0
  19. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/vm_setup/docker/docker_setup.yml +0 -0
  20. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/vm_setup/docker/login_to_docker_hub.yml +0 -0
  21. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/vm_setup/dynamic_inventory.yml +0 -0
  22. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/vm_setup/inventory.yml +0 -0
  23. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool/vm_setup/project_service.yml +0 -0
  24. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool.egg-info/SOURCES.txt +0 -0
  25. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool.egg-info/dependency_links.txt +0 -0
  26. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool.egg-info/entry_points.txt +0 -0
  27. {vm_tool-1.0.21 → vm_tool-1.0.24}/vm_tool.egg-info/requires.txt +0 -0
  28. {vm_tool-1.0.21 → vm_tool-1.0.24}/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.21
3
+ Version: 1.0.24
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
@@ -86,6 +86,7 @@ config = SetupRunnerConfig(
86
86
  github_username='your_github_username', # Required if the repository is private, e.g., username
87
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
+ github_branch='your_branch_name', # Optional, defaults to 'main'
89
90
  docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
90
91
  dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
91
92
  dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
@@ -120,6 +121,7 @@ config = SetupRunnerConfig(
120
121
  github_username='your_github_username', # Required if the repository is private, e.g., username
121
122
  github_token='your_github_token', # Required if the repository is private, e.g., token
122
123
  github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
124
+ github_branch='your_branch_name', # Optional, defaults to 'main'
123
125
  docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
124
126
  dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
125
127
  dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
@@ -130,13 +132,15 @@ runner = SetupRunner(config)
130
132
  ssh_configs = [
131
133
  SSHConfig(
132
134
  ssh_username='your_ssh_username_1', # e.g., ssh_user_1
133
- ssh_password='your_ssh_password_1', # e.g., ssh_password_1
134
- ssh_hostname='your_ssh_hostname_1' # e.g., ssh1.example.com
135
+ ssh_password='your_ssh_password_1', # Optional, only use if you don’t want to use SSH key
136
+ ssh_hostname='your_ssh_hostname_1', # e.g., ssh1.example.com
137
+ ssh_identity_file='/path/to/your/ssh_key_1' # Optional, path to SSH Identity file
135
138
  ),
136
139
  SSHConfig(
137
140
  ssh_username='your_ssh_username_2', # e.g., ssh_user_2
138
- ssh_password='your_ssh_password_2', # e.g., ssh_password_2
139
- ssh_hostname='your_ssh_hostname_2' # e.g., ssh2.example.com
141
+ ssh_password='your_ssh_password_2', # Optional, only use if you don’t want to use SSH key
142
+ ssh_hostname='your_ssh_hostname_2', # e.g., ssh2.example.com
143
+ ssh_key='/path/to/your/ssh_key_2' # Optional, path to SSH Identity file
140
144
  )
141
145
  # Add more SSHConfig instances as needed
142
146
  ]
@@ -32,6 +32,7 @@ config = SetupRunnerConfig(
32
32
  github_username='your_github_username', # Required if the repository is private, e.g., username
33
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
+ github_branch='your_branch_name', # Optional, defaults to 'main'
35
36
  docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
36
37
  dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
37
38
  dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
@@ -66,6 +67,7 @@ config = SetupRunnerConfig(
66
67
  github_username='your_github_username', # Required if the repository is private, e.g., username
67
68
  github_token='your_github_token', # Required if the repository is private, e.g., token
68
69
  github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
70
+ github_branch='your_branch_name', # Optional, defaults to 'main'
69
71
  docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
70
72
  dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
71
73
  dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
@@ -76,13 +78,15 @@ runner = SetupRunner(config)
76
78
  ssh_configs = [
77
79
  SSHConfig(
78
80
  ssh_username='your_ssh_username_1', # e.g., ssh_user_1
79
- ssh_password='your_ssh_password_1', # e.g., ssh_password_1
80
- ssh_hostname='your_ssh_hostname_1' # e.g., ssh1.example.com
81
+ ssh_password='your_ssh_password_1', # Optional, only use if you don’t want to use SSH key
82
+ ssh_hostname='your_ssh_hostname_1', # e.g., ssh1.example.com
83
+ ssh_identity_file='/path/to/your/ssh_key_1' # Optional, path to SSH Identity file
81
84
  ),
82
85
  SSHConfig(
83
86
  ssh_username='your_ssh_username_2', # e.g., ssh_user_2
84
- ssh_password='your_ssh_password_2', # e.g., ssh_password_2
85
- ssh_hostname='your_ssh_hostname_2' # e.g., ssh2.example.com
87
+ ssh_password='your_ssh_password_2', # Optional, only use if you don’t want to use SSH key
88
+ ssh_hostname='your_ssh_hostname_2', # e.g., ssh2.example.com
89
+ ssh_key='/path/to/your/ssh_key_2' # Optional, path to SSH Identity file
86
90
  )
87
91
  # Add more SSHConfig instances as needed
88
92
  ]
@@ -11,7 +11,7 @@ else:
11
11
 
12
12
  setup(
13
13
  name='vm_tool',
14
- version='1.0.21', # This will be updated by bump2version
14
+ version='1.0.24', # 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.21')
5
+ parser.add_argument('--version', action='version', version='1.0.24')
6
6
 
7
7
  args = parser.parse_args()
8
8
 
@@ -2,75 +2,123 @@ import sys
2
2
  import ansible_runner
3
3
  import os
4
4
  import yaml
5
- from pydantic import BaseModel, validator
5
+ from pydantic import BaseModel, validator, model_validator
6
6
  from typing import List, Optional
7
7
 
8
8
  class SetupRunnerConfig(BaseModel):
9
+ """
10
+ Configuration model for setting up the runner.
11
+
12
+ Attributes:
13
+ github_username (Optional[str]): GitHub username for authentication.
14
+ github_token (Optional[str]): GitHub token for authentication.
15
+ github_project_url (str): URL of the GitHub repository.
16
+ github_branch (str): GitHub branch to use (default: 'main').
17
+ docker_compose_file_path (str): Path to the Docker Compose file (default: 'docker-compose.yml').
18
+ dockerhub_username (Optional[str]): DockerHub username (optional).
19
+ dockerhub_password (Optional[str]): DockerHub password (required if username is provided).
20
+ """
21
+
9
22
  github_username: Optional[str] = None
10
23
  github_token: Optional[str] = None
11
24
  github_project_url: str
25
+ github_branch: str = "main" # Default to main branch
12
26
  docker_compose_file_path: str = 'docker-compose.yml'
13
27
  dockerhub_username: Optional[str] = None
14
28
  dockerhub_password: Optional[str] = None
15
29
 
16
30
  @validator('docker_compose_file_path', pre=True, always=True)
17
31
  def set_default_docker_compose_file_path(cls, v):
32
+ """Ensures a default value for the Docker Compose file path."""
18
33
  return v or 'docker-compose.yml'
19
34
 
20
35
  @validator('dockerhub_password', always=True)
21
36
  def check_dockerhub_password(cls, v, values):
37
+ """Ensures that a password is provided if a DockerHub username is set."""
22
38
  if values.get('dockerhub_username') and not v:
23
39
  raise ValueError("DockerHub password must be provided if DockerHub username is specified")
24
40
  return v
25
-
41
+
26
42
  @validator('dockerhub_username', always=True)
27
43
  def check_dockerhub_username(cls, v, values):
44
+ """Ensures that a username is provided if a DockerHub password is set."""
28
45
  if values.get('dockerhub_password') and not v:
29
46
  raise ValueError("DockerHub username must be provided if DockerHub password is specified")
30
47
  return v
31
-
48
+
32
49
  @validator('github_token', always=True)
33
50
  def check_github_token(cls, v, values):
51
+ """Ensures that a GitHub token is provided if a GitHub username is set."""
34
52
  if values.get('github_username') and not v:
35
53
  raise ValueError("GitHub token must be provided if GitHub username is specified")
36
54
  return v
37
-
55
+
38
56
  @validator('github_username', always=True)
39
57
  def check_github_username(cls, v, values):
58
+ """Ensures that a GitHub username is provided if a GitHub token is set."""
40
59
  if values.get('github_token') and not v:
41
60
  raise ValueError("GitHub username must be provided if GitHub token is specified")
42
61
  return v
43
62
 
44
63
  class SSHConfig(BaseModel):
64
+ """
65
+ Configuration model for SSH authentication.
66
+
67
+ Attributes:
68
+ ssh_username (str): SSH username.
69
+ ssh_hostname (str): SSH host/IP.
70
+ ssh_password (Optional[str]): SSH password (optional if identity file is provided).
71
+ ssh_identity_file (Optional[str]): Path to SSH private key file (optional if password is provided).
72
+ """
73
+
45
74
  ssh_username: str
46
- ssh_password: str
47
75
  ssh_hostname: str
76
+ ssh_password: Optional[str] = None
77
+ ssh_identity_file: Optional[str] = None
78
+
79
+ @model_validator(mode="before")
80
+ def validate_authentication(cls, values):
81
+ """Ensures that either an SSH password or identity file is provided for authentication."""
82
+ password = values.get('ssh_password')
83
+ identity_file = values.get('ssh_identity_file')
84
+ if not password and not identity_file:
85
+ raise ValueError("Either ssh_password or ssh_identity_file must be provided.")
86
+ return values
48
87
 
49
88
  class SetupRunner:
89
+ """
90
+ Main class to handle setup execution.
91
+
92
+ Attributes:
93
+ github_username (str): GitHub username.
94
+ github_token (str): GitHub token.
95
+ github_project_url (str): GitHub repository URL.
96
+ github_branch (str): GitHub branch to use.
97
+ docker_compose_file_path (str): Path to Docker Compose file.
98
+ dockerhub_username (str): DockerHub username.
99
+ dockerhub_password (str): DockerHub password.
100
+ """
101
+
50
102
  def __init__(self, config: SetupRunnerConfig):
103
+ """Initializes the setup runner with the given configuration."""
51
104
  self.github_username = config.github_username
52
105
  self.github_token = config.github_token
53
106
  self.github_project_url = config.github_project_url
107
+ self.github_branch = config.github_branch
54
108
  self.docker_compose_file_path = config.docker_compose_file_path
55
109
  self.dockerhub_username = config.dockerhub_username
56
110
  self.dockerhub_password = config.dockerhub_password
57
111
 
58
112
  def _run_ansible_playbook(self, extravars, inventory_file):
59
- # Get the current directory of this script
113
+ """Executes an Ansible playbook with the given variables and inventory."""
60
114
  current_dir = os.path.dirname(os.path.abspath(__file__))
61
-
62
- # Get the virtual environment directory
63
115
  venv_dir = os.path.join(sys.prefix, 'ansible_runner_data')
64
-
65
- # Ensure the directory exists
66
116
  os.makedirs(venv_dir, exist_ok=True)
67
117
 
68
- # Construct dynamic paths
69
118
  playbook_path = os.path.join(current_dir, 'vm_setup', 'main.yml')
70
119
  inventory_path = os.path.join(current_dir, 'vm_setup', inventory_file)
71
120
 
72
121
  try:
73
- # Run the Ansible playbook using ansible-runner
74
122
  r = ansible_runner.run(
75
123
  private_data_dir=venv_dir,
76
124
  playbook=playbook_path,
@@ -85,11 +133,12 @@ class SetupRunner:
85
133
  raise RuntimeError(f"An error occurred while running the Ansible playbook: {str(e)}")
86
134
 
87
135
  def run_setup(self):
88
- # Construct extravars dictionary
136
+ """Runs the setup process using Ansible."""
89
137
  extravars = {
90
138
  'GITHUB_USERNAME': self.github_username,
91
139
  'GITHUB_TOKEN': self.github_token,
92
140
  'GITHUB_PROJECT_URL': self.github_project_url,
141
+ 'GITHUB_BRANCH': self.github_branch,
93
142
  'DOCKERHUB_USERNAME': self.dockerhub_username,
94
143
  'DOCKERHUB_PASSWORD': self.dockerhub_password,
95
144
  'EXECUTION_TYPE': "normal"
@@ -101,10 +150,9 @@ class SetupRunner:
101
150
  self._run_ansible_playbook(extravars, 'inventory.yml')
102
151
 
103
152
  def run_cloud_setup(self, ssh_configs: List[SSHConfig]):
104
- # Define the path for the dynamic inventory file
153
+ """Runs the cloud setup using Ansible with dynamic inventory generation."""
105
154
  inventory_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'vm_setup', 'dynamic_inventory.yml')
106
155
 
107
- # Create dynamic inventory content
108
156
  inventory_content = {
109
157
  'all': {
110
158
  'hosts': {},
@@ -116,21 +164,25 @@ class SetupRunner:
116
164
 
117
165
  for i, ssh_config in enumerate(ssh_configs):
118
166
  host_key = f'cloud_host_{i}'
119
- inventory_content['all']['hosts'][host_key] = {
167
+ host_entry = {
120
168
  'ansible_host': ssh_config.ssh_hostname,
121
169
  'ansible_user': ssh_config.ssh_username,
122
- 'ansible_ssh_pass': ssh_config.ssh_password
123
170
  }
171
+ if ssh_config.ssh_identity_file:
172
+ host_entry['ansible_ssh_private_key_file'] = ssh_config.ssh_identity_file
173
+ elif ssh_config.ssh_password:
174
+ host_entry['ansible_ssh_pass'] = ssh_config.ssh_password
175
+
176
+ inventory_content['all']['hosts'][host_key] = host_entry
124
177
 
125
- # Write dynamic inventory to a file
126
178
  with open(inventory_file_path, 'w') as inventory_file:
127
179
  yaml.dump(inventory_content, inventory_file)
128
180
 
129
- # Construct extravars dictionary
130
181
  extravars = {
131
182
  'GITHUB_USERNAME': self.github_username,
132
183
  'GITHUB_TOKEN': self.github_token,
133
184
  'GITHUB_PROJECT_URL': self.github_project_url,
185
+ 'GITHUB_BRANCH': self.github_branch,
134
186
  'DOCKERHUB_USERNAME': self.dockerhub_username,
135
187
  'DOCKERHUB_PASSWORD': self.dockerhub_password,
136
188
  'EXECUTION_TYPE': "cloud"
@@ -10,10 +10,28 @@
10
10
  register: docker_compose_installed
11
11
  ignore_errors: yes
12
12
 
13
- # - name: Update apt package index
14
- # ansible.builtin.apt:
15
- # update_cache: yes
16
- # when: docker_installed.rc != 0 or docker_compose_installed.rc != 0
13
+ - name: Log Docker installation status
14
+ ansible.builtin.debug:
15
+ msg: "Docker is {{ 'installed' if docker_installed.rc == 0 else 'not installed' }}"
16
+
17
+ - name: Log Docker Compose installation status
18
+ ansible.builtin.debug:
19
+ msg: "Docker Compose is {{ 'installed' if docker_compose_installed.rc == 0 else 'not installed' }}"
20
+
21
+ - name: Get system architecture
22
+ ansible.builtin.command: dpkg --print-architecture
23
+ register: system_arch
24
+ changed_when: false
25
+
26
+ - name: Get Ubuntu version codename
27
+ ansible.builtin.command: lsb_release -cs
28
+ register: ubuntu_codename
29
+ changed_when: false
30
+
31
+ - name: Update apt package index
32
+ ansible.builtin.apt:
33
+ update_cache: yes
34
+ when: docker_installed.rc != 0 or docker_compose_installed.rc != 0
17
35
 
18
36
  - name: Install prerequisites
19
37
  ansible.builtin.apt:
@@ -25,6 +43,7 @@
25
43
  - lsb-release
26
44
  - software-properties-common
27
45
  state: present
46
+ when: docker_installed.rc != 0 or docker_compose_installed.rc != 0
28
47
 
29
48
  - name: Add Docker GPG key
30
49
  ansible.builtin.shell:
@@ -32,14 +51,14 @@
32
51
  curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --yes --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
33
52
  when: docker_installed.rc != 0 or docker_compose_installed.rc != 0
34
53
 
35
- - name: Add Docker repository
54
+ - name: Determine correct Ubuntu codename
55
+ set_fact:
56
+ ubuntu_codename_fixed: "{{ 'jammy' if ubuntu_codename.stdout == 'noble' else ubuntu_codename.stdout }}"
57
+
58
+ - name: Add Docker repository (auto-detect architecture)
36
59
  ansible.builtin.shell:
37
60
  cmd: |
38
- echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
39
- when: docker_installed.rc != 0 or docker_compose_installed.rc != 0
40
-
41
- - name: Set up the Docker stable repository
42
- ansible.builtin.command: echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
61
+ echo "deb [arch={{ system_arch.stdout }} signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu {{ ubuntu_codename_fixed }} stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
43
62
  when: docker_installed.rc != 0 or docker_compose_installed.rc != 0
44
63
 
45
64
  - name: Update apt package index again
@@ -47,7 +66,7 @@
47
66
  update_cache: yes
48
67
  when: docker_installed.rc != 0 or docker_compose_installed.rc != 0
49
68
 
50
- - name: Install Docker and Docker Compose
69
+ - name: Install Docker and Docker Compose (if available in repo)
51
70
  ansible.builtin.apt:
52
71
  name:
53
72
  - docker-ce
@@ -55,6 +74,8 @@
55
74
  - containerd.io
56
75
  - docker-compose-plugin
57
76
  state: present
77
+ ignore_errors: yes
78
+ register: docker_install_status
58
79
  when: docker_installed.rc != 0 or docker_compose_installed.rc != 0
59
80
 
60
81
  - name: Enable and Start Docker service
@@ -62,9 +83,10 @@
62
83
  name: docker
63
84
  enabled: yes
64
85
  state: started
65
- when: docker_installed.rc != 0
66
-
86
+ when: docker_installed.rc != 0 or docker_compose_installed.rc != 0
87
+
67
88
  - name: Change permissions for Docker socket
68
89
  ansible.builtin.command: sudo chmod 666 /var/run/docker.sock
69
90
  ignore_errors: yes
91
+ when: docker_installed.rc != 0 or docker_compose_installed.rc != 0
70
92
  become: yes
@@ -1,5 +1,11 @@
1
1
  - name: Git Configuration Playbook
2
2
  block:
3
+ - name: Ensure Git is installed
4
+ package:
5
+ name: git
6
+ state: present
7
+ become: yes
8
+
3
9
  - name: Configure Git with GitHub token
4
10
  shell: |
5
11
  git config --global credential.helper store
@@ -7,16 +13,27 @@
7
13
  become: yes
8
14
  when: GITHUB_TOKEN is defined and GITHUB_USERNAME is defined
9
15
 
16
+ - name: Check if project directory exists
17
+ stat:
18
+ path: "{{ project_dest_dir }}"
19
+ register: project_dir_stat
20
+
10
21
  - name: Remove existing Project repository if present
11
22
  file:
12
23
  path: "{{ project_dest_dir }}"
13
24
  state: absent
14
25
  force: yes
15
26
  become: yes
27
+ when: project_dir_stat.stat.exists
28
+
29
+ - name: Log the GitHub repository being cloned
30
+ debug:
31
+ msg: "Cloning repository from {{ GITHUB_PROJECT_URL }} (branch: {{ GITHUB_BRANCH }})"
16
32
 
17
- - name: Clone the Project repository
33
+ - name: Clone the Project repository with shallow clone
18
34
  git:
19
35
  repo: "{{ GITHUB_PROJECT_URL }}"
20
36
  dest: "{{ project_dest_dir }}"
21
- version: main
22
- become: yes
37
+ version: "{{ GITHUB_BRANCH }}"
38
+ depth: 1
39
+ become: yes
@@ -2,9 +2,6 @@
2
2
  hosts: all
3
3
  gather_facts: yes
4
4
 
5
- vars:
6
- static_playbook_dir: "{{ playbook_dir }}"
7
-
8
5
  tasks:
9
6
  - name: Setup
10
7
  include_tasks: setup.yml
@@ -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.21
3
+ Version: 1.0.24
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
@@ -86,6 +86,7 @@ config = SetupRunnerConfig(
86
86
  github_username='your_github_username', # Required if the repository is private, e.g., username
87
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
+ github_branch='your_branch_name', # Optional, defaults to 'main'
89
90
  docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
90
91
  dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
91
92
  dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
@@ -120,6 +121,7 @@ config = SetupRunnerConfig(
120
121
  github_username='your_github_username', # Required if the repository is private, e.g., username
121
122
  github_token='your_github_token', # Required if the repository is private, e.g., token
122
123
  github_project_url='your_github_project_url', # e.g., https://github.com/username/repo
124
+ github_branch='your_branch_name', # Optional, defaults to 'main'
123
125
  docker_compose_file_path='path_to_your_docker_compose_file', # Optional, defaults to 'docker-compose.yml'
124
126
  dockerhub_username='your_dockerhub_username', # Required if DockerHub login is needed, e.g., dockerhub_user
125
127
  dockerhub_password='your_dockerhub_password' # Required if DockerHub login is needed, e.g., dockerhub_password
@@ -130,13 +132,15 @@ runner = SetupRunner(config)
130
132
  ssh_configs = [
131
133
  SSHConfig(
132
134
  ssh_username='your_ssh_username_1', # e.g., ssh_user_1
133
- ssh_password='your_ssh_password_1', # e.g., ssh_password_1
134
- ssh_hostname='your_ssh_hostname_1' # e.g., ssh1.example.com
135
+ ssh_password='your_ssh_password_1', # Optional, only use if you don’t want to use SSH key
136
+ ssh_hostname='your_ssh_hostname_1', # e.g., ssh1.example.com
137
+ ssh_identity_file='/path/to/your/ssh_key_1' # Optional, path to SSH Identity file
135
138
  ),
136
139
  SSHConfig(
137
140
  ssh_username='your_ssh_username_2', # e.g., ssh_user_2
138
- ssh_password='your_ssh_password_2', # e.g., ssh_password_2
139
- ssh_hostname='your_ssh_hostname_2' # e.g., ssh2.example.com
141
+ ssh_password='your_ssh_password_2', # Optional, only use if you don’t want to use SSH key
142
+ ssh_hostname='your_ssh_hostname_2', # e.g., ssh2.example.com
143
+ ssh_key='/path/to/your/ssh_key_2' # Optional, path to SSH Identity file
140
144
  )
141
145
  # Add more SSHConfig instances as needed
142
146
  ]
@@ -1,5 +0,0 @@
1
- - name: Setup VM
2
- block:
3
- - name: Set project_dest_dir variable
4
- set_fact:
5
- project_dest_dir: "{{ static_playbook_dir }}/project"
File without changes
File without changes
File without changes
File without changes
File without changes