Skip to content

Commit b7dd156

Browse files
authored
Merge pull request #2 from ansible-actions/b
Add requiremed pip package
2 parents cb25598 + b8244f1 commit b7dd156

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ inputs:
2222
You can define a required ansible role here.
2323
They will be installed using ansible-galaxy role install <YourInput>.
2424
required: false
25+
python_dependency:
26+
description: |
27+
Install a Python Package using pip
28+
They will be installed using pip install <YourInput>.
29+
required: false
2530
```
2631
2732
## Example Setup
@@ -46,7 +51,7 @@ jobs:
4651
fetch-depth: 0
4752

4853
- name: Run ansible-lint
49-
uses: ansible-actions/[email protected].2
54+
uses: ansible-actions/[email protected].3
5055
with:
5156
target: "site.yml"
5257
```

action.yml

+6
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ inputs:
1919
You can define a required ansible role here.
2020
They will be installed using ansible-galaxy role install <YourInput>.
2121
required: false
22+
python_dependency:
23+
description: |
24+
Install a Python Package using pip
25+
They will be installed using pip install <YourInput>.
26+
required: false
2227
runs:
2328
using: docker
2429
image: Dockerfile
2530
env:
2631
TARGET: ${{ inputs.target }}
2732
REQCOLLECTIONS: ${{ inputs.required_collections }}
2833
REQROLES: ${{ inputs.required_roles }}
34+
PIPPACKAGE: ${{ inputs.python_dependency }}
2935
branding:
3036
icon: 'check-circle'
3137
color: 'blue'

ansible_docker.py

+11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def run_command(self, command):
5959
ENV_TARGET_NAME = "TARGET"
6060
ENV_REQUIRED_COLLECTION_NAME = "REQCOLLECTIONS"
6161
ENV_REQUIRED_ROLE_NAME = "REROLE"
62+
ENV_PIPPACKAGE_NAME = "PIPPACKAGE"
6263

6364
# check for target variable
6465
env_target = EnvironmentManager(ENV_TARGET_NAME)
@@ -75,6 +76,10 @@ def run_command(self, command):
7576
env_role = EnvironmentManager(ENV_REQUIRED_ROLE_NAME)
7677
reqired_role = env_role.check_optional_environment_variable()
7778

79+
# check for required role variable
80+
env_pip = EnvironmentManager(ENV_PIPPACKAGE_NAME)
81+
pip_pkg = env_pip.check_optional_environment_variable()
82+
7883
# run ansible commands
7984
ansible_version_checker = AnsibleCommandExecution()
8085

@@ -91,6 +96,12 @@ def run_command(self, command):
9196
version_info = ansible_version_checker.run_command(ansible_command)
9297
print(f"ROLE INSTALL SUCCESSFUL\n{version_info}")
9398

99+
# Optionally install pip package
100+
if bool(pip_pkg):
101+
ansible_command = ["pip", "install", "--upgrade", f"{pip_pkg}"]
102+
version_info = ansible_version_checker.run_command(ansible_command)
103+
print(f"PIP PACKAGE INSTALL SUCCESSFUL\n{version_info}")
104+
94105
# run ansible lint
95106
ansible_command = ["ansible-lint", f"{target}"]
96107
linter_run = ansible_version_checker.run_command(ansible_command)

0 commit comments

Comments
 (0)