vm-tool 1.0.12__tar.gz → 1.0.13__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: vm_tool
3
- Version: 1.0.12
3
+ Version: 1.0.13
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.12', # This will be updated by bump2version
14
+ version='1.0.13', # 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.12')
5
+ parser.add_argument('--version', action='version', version='1.0.13')
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(
@@ -0,0 +1,8 @@
1
+ all:
2
+ hosts:
3
+ cloud_host:
4
+ ansible_host: "{{ SSH_HOSTNAME }}"
5
+ ansible_user: "{{ SSH_USERNAME }}"
6
+ ansible_ssh_pass: "{{ SSH_PASSWORD }}"
7
+ vars:
8
+ ansible_python_interpreter: /usr/bin/python3
@@ -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://{{ github_username }}:{{ github_token }}@github.com" > ~/.git-credentials
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: "{{ project_repo_url }}"
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: "{{ github_project_url }}"
76
- GITHUB_USERNAME: "{{ github_username }}"
77
- GITHUB_TOKEN: "{{ 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.12
3
+ Version: 1.0.13
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