Skip to content

Commit a3635e0

Browse files
committed
Added ansible scripts
1 parent 94fb1a7 commit a3635e0

17 files changed

Lines changed: 545 additions & 3 deletions

File tree

script/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MLCommons Automation Scripts
22

3-
*Last updated: 2026-06-14 16:16:11*
3+
*Last updated: 2026-06-21 19:18:29*
44

55
This directory contains automation scripts for MLPerf benchmarks, AI/ML workflows, and development operations.
66

@@ -348,6 +348,9 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow
348348
- **[install-terraform-from-src](install-terraform-from-src/)**
349349
- install-terraform-from-src
350350
- Tags: `install`, `terraform`, `from-src`
351+
- **[run-ansible](run-ansible/)**
352+
- run-ansible
353+
- Tags: `run`, `ansible`, `remote`, `configuration-management`
351354
- **[run-terraform](run-terraform/)**
352355
- run-terraform
353356
- Tags: `run`, `terraform`
@@ -456,6 +459,9 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow
456459
- **[get-android-sdk](get-android-sdk/)**
457460
- get-android-sdk
458461
- Tags: `get`, `android`, `sdk`, `android-sdk`
462+
- **[get-ansible](get-ansible/)**
463+
- get-ansible
464+
- Tags: `get`, `ansible`, `get-ansible`
459465
- **[get-apptainer](get-apptainer/)**
460466
- get-apptainer
461467
- Tags: `get-apptainer`
@@ -582,6 +588,9 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow
582588
- **[get-zendnn](get-zendnn/)**
583589
- get-zendnn
584590
- Tags: `get`, `zendnn`, `amd`, `from.src`
591+
- **[install-ansible-via-pip](install-ansible-via-pip/)**
592+
- install-ansible-via-pip
593+
- Tags: `install`, `ansible`, `via-pip`
585594
- **[install-apt-package](install-apt-package/)**
586595
- install-apt-package
587596
- Tags: `get`, `install`, `apt-package`, `package`
@@ -1244,8 +1253,8 @@ This directory contains automation scripts for MLPerf benchmarks, AI/ML workflow
12441253

12451254
## Statistics
12461255

1247-
- **Total Scripts**: 366
1248-
- **Categories**: 35
1256+
- **Total Scripts**: 368
1257+
- **Categories**: 34
12491258

12501259
## Usage
12511260

script/get-ansible/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Get Ansible
2+
3+
This MLC script detects or installs Ansible.
4+
5+
## Usage
6+
7+
```bash
8+
# Detect ansible (installs if not found)
9+
mlcr get,ansible
10+
```
11+
12+
## Exported Environment
13+
14+
| Variable | Description |
15+
|----------|-------------|
16+
| `MLC_ANSIBLE_BIN_WITH_PATH` | Full path to ansible-playbook binary |
17+
| `MLC_ANSIBLE_INSTALLED_PATH` | Directory containing ansible binaries |
18+
| `MLC_ANSIBLE_VERSION` | Detected ansible version |

script/get-ansible/customize.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from mlc import utils
2+
import os
3+
4+
5+
def preprocess(i):
6+
7+
os_info = i['os_info']
8+
env = i['env']
9+
recursion_spaces = i['recursion_spaces']
10+
11+
file_name = 'ansible-playbook.exe' if os_info['platform'] == 'windows' else 'ansible-playbook'
12+
env['FILE_NAME'] = file_name
13+
14+
if 'MLC_ANSIBLE_BIN_WITH_PATH' not in env:
15+
r = i['automation'].find_artifact({'file_name': file_name,
16+
'env': env,
17+
'os_info': os_info,
18+
'default_path_env_key': 'PATH',
19+
'detect_version': True,
20+
'env_path_key': 'MLC_ANSIBLE_BIN_WITH_PATH',
21+
'run_script_input': i['run_script_input'],
22+
'recursion_spaces': recursion_spaces})
23+
if r['return'] > 0:
24+
if r['return'] == 16:
25+
env['MLC_REQUIRE_INSTALL'] = "yes"
26+
return {'return': 0}
27+
else:
28+
return r
29+
30+
return {'return': 0}
31+
32+
33+
def detect_version(i):
34+
r = i['automation'].parse_version({'match_text': r'ansible.*?(\d+\.\d+\.\d+)',
35+
'group_number': 1,
36+
'env_key': 'MLC_ANSIBLE_VERSION',
37+
'which_env': i['env']})
38+
if r['return'] > 0:
39+
return r
40+
41+
logger = i['automation'].logger
42+
version = r['version']
43+
44+
logger.info(
45+
i['recursion_spaces'] +
46+
' Detected version: {}'.format(version))
47+
return {'return': 0, 'version': version}
48+
49+
50+
def postprocess(i):
51+
env = i['env']
52+
53+
r = detect_version(i)
54+
if r['return'] > 0:
55+
return r
56+
57+
version = r['version']
58+
found_file_path = env['MLC_ANSIBLE_BIN_WITH_PATH']
59+
found_path = os.path.dirname(found_file_path)
60+
61+
env['MLC_ANSIBLE_INSTALLED_PATH'] = found_path
62+
env['MLC_ANSIBLE_CACHE_TAGS'] = 'version-' + version
63+
64+
return {'return': 0, 'version': version}

script/get-ansible/meta.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
alias: get-ansible
2+
uid: a3b7c9d2e5f84610
3+
automation_alias: script
4+
automation_uid: 5b4e0237da074764
5+
6+
# Metadata
7+
category: Detection or installation of tools and artifacts
8+
tags:
9+
- get
10+
- ansible
11+
- get-ansible
12+
13+
# Cache
14+
cache: true
15+
clean_files: []
16+
17+
# Environment
18+
new_env_keys:
19+
- MLC_ANSIBLE_*
20+
- +PATH
21+
22+
# Dependencies
23+
deps:
24+
- tags: get,python3
25+
26+
prehook_deps:
27+
- enable_if_env:
28+
MLC_REQUIRE_INSTALL:
29+
- 'yes'
30+
tags: install,ansible,via-pip

script/get-ansible/run.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
ansible-playbook --version > tmp-ver.out
3+
IF %ERRORLEVEL% NEQ 0 EXIT /b 1

script/get-ansible/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
ansible-playbook --version > tmp-ver.out
3+
test $? -eq 0 || exit 1
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Install Ansible via pip
2+
3+
This MLC script installs Ansible using pip.
4+
5+
## Usage
6+
7+
```bash
8+
# Install latest ansible
9+
mlcr install,ansible,via-pip
10+
11+
# Install a specific version
12+
mlcr install,ansible,via-pip --version=9.0
13+
```
14+
15+
## Dependencies
16+
17+
- Python 3
18+
- pip
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from mlc import utils
2+
import os
3+
4+
5+
def preprocess(i):
6+
7+
env = i['env']
8+
9+
package = env.get('MLC_ANSIBLE_PIP_PACKAGE', 'ansible')
10+
version = env.get('MLC_ANSIBLE_VERSION_TO_INSTALL', '')
11+
12+
if version:
13+
env['MLC_ANSIBLE_PIP_INSTALL_STRING'] = f'{package}=={version}'
14+
else:
15+
env['MLC_ANSIBLE_PIP_INSTALL_STRING'] = package
16+
17+
return {'return': 0}
18+
19+
20+
def postprocess(i):
21+
env = i['env']
22+
import shutil
23+
24+
ansible_bin = shutil.which('ansible-playbook')
25+
if ansible_bin:
26+
env['MLC_ANSIBLE_BIN_WITH_PATH'] = ansible_bin
27+
env['MLC_ANSIBLE_INSTALLED_PATH'] = os.path.dirname(ansible_bin)
28+
env['+PATH'] = [os.path.dirname(ansible_bin)]
29+
30+
return {'return': 0}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
alias: install-ansible-via-pip
2+
uid: b4c8d1e7f3a24956
3+
automation_alias: script
4+
automation_uid: 5b4e0237da074764
5+
6+
# Metadata
7+
category: Detection or installation of tools and artifacts
8+
tags:
9+
- install
10+
- ansible
11+
- via-pip
12+
13+
# Environment
14+
default_env:
15+
MLC_ANSIBLE_PIP_PACKAGE: ansible
16+
new_env_keys:
17+
- MLC_ANSIBLE_*
18+
- +PATH
19+
20+
# Input mapping
21+
input_mapping:
22+
version: MLC_ANSIBLE_VERSION_TO_INSTALL
23+
24+
# Dependencies
25+
deps:
26+
- tags: get,python3
27+
- tags: get,generic-python-lib,_pip
28+
29+
# Versions
30+
default_version: latest
31+
versions:
32+
latest:
33+
env: {}
34+
'9.0':
35+
env:
36+
MLC_ANSIBLE_VERSION_TO_INSTALL: '9.0'
37+
'10.0':
38+
env:
39+
MLC_ANSIBLE_VERSION_TO_INSTALL: '10.0'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@echo off
2+
3+
echo Installing Ansible via pip...
4+
"%MLC_PYTHON_BIN_WITH_PATH%" -m pip install %MLC_ANSIBLE_PIP_INSTALL_STRING%
5+
IF %ERRORLEVEL% NEQ 0 EXIT /b 1
6+
7+
echo.
8+
echo Ansible installed successfully.
9+
ansible --version

0 commit comments

Comments
 (0)