Skip to content

Commit 0945665

Browse files
committed
Install ansible-runner-http as local python package
Signed-off-by: chiragkyal <ckyal@redhat.com>
1 parent 27bbbbb commit 0945665

6 files changed

Lines changed: 169 additions & 90 deletions

File tree

images/ansible-operator/Dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ RUN rustc --version
1111

1212
# Copy python dependencies (including ansible) to be installed using Pipenv
1313
COPY images/ansible-operator/Pipfile* ./
14+
# Copy our local ansible-runner-http replacement module
15+
COPY images/ansible-operator/ansible_runner_http ./ansible_runner_http
16+
COPY images/ansible-operator/setup.py ./setup.py
1417
# Instruct pip(env) not to keep a cache of installed packages,
1518
# to install into the global site-packages and
1619
# to clear the pipenv cache as well
1720
ENV PIP_NO_CACHE_DIR=1 \
18-
PIPENV_SYSTEM=1 \
19-
PIPENV_CLEAR=1
21+
PIPENV_SYSTEM=1 \
22+
PIPENV_CLEAR=1
2023
# Ensure fresh metadata rather than cached metadata, install system and pip python deps,
2124
# and remove those not needed at runtime.
2225
RUN set -e && dnf clean all && rm -rf /var/cache/dnf/* \
@@ -27,6 +30,7 @@ RUN set -e && dnf clean all && rm -rf /var/cache/dnf/* \
2730
&& pip3 install --upgrade pip~=23.3.2 \
2831
&& pip3 install pipenv==2023.11.15 \
2932
&& pipenv install --deploy \
33+
&& pip3 install . \
3034
&& pipenv check \
3135
&& dnf remove -y gcc libffi-devel openssl-devel python3.12-devel \
3236
&& dnf clean all \
@@ -63,8 +67,8 @@ RUN curl -L -o /tini https://github.com/krallin/tini/releases/download/${TINI_VE
6367
FROM base AS final
6468

6569
ENV HOME=/opt/ansible \
66-
USER_NAME=ansible \
67-
USER_UID=1001
70+
USER_NAME=ansible \
71+
USER_UID=1001
6872

6973
# Ensure directory permissions are properly set
7074
RUN echo "${USER_NAME}:x:${USER_UID}:0:${USER_NAME} user:${HOME}:/sbin/nologin" >> /etc/passwd \

images/ansible-operator/Pipfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ name = "pypi"
55

66
[packages]
77
ansible-runner = "~=2.4.0"
8-
ansible-runner-http = "~=1.0.0"
8+
requests = "~=2.32.5"
9+
requests-unixsocket = "==0.4.1"
910
ansible-core = "~=2.18.3"
1011
urllib3 = "~=2.5.0"
1112
kubernetes = "==33.1.0"
12-
requests = "~=2.32.5"
1313

1414
[dev-packages]
1515

images/ansible-operator/Pipfile.lock

Lines changed: 94 additions & 84 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .events import status_handler, event_handler # noqa
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import os
2+
import requests
3+
import requests_unixsocket
4+
import logging
5+
6+
logger = logging.getLogger('ansible-runner')
7+
8+
def send_request(url, data, headers={}, urlpath=None):
9+
if os.path.exists(url):
10+
url_actual = "http+unix://{}".format(url.replace("/", "%2F"))
11+
if urlpath is not None:
12+
url_actual += urlpath
13+
session = requests_unixsocket.Session()
14+
else:
15+
url_actual = url
16+
session = requests.Session()
17+
logger.debug("Sending payload to {}".format(url_actual))
18+
return session.post(url_actual, headers=headers, json=(data))
19+
20+
21+
def get_configuration(runner_config):
22+
runner_url = runner_config.settings.get("runner_http_url", None)
23+
runner_url = os.getenv("RUNNER_HTTP_URL", runner_url)
24+
runner_path = runner_config.settings.get("runner_http_path", None)
25+
runner_path = os.getenv("RUNNER_HTTP_PATH", runner_path)
26+
runner_headers = runner_config.settings.get("runner_http_headers", None)
27+
return dict(runner_url=runner_url,
28+
runner_path=runner_path,
29+
runner_headers=runner_headers)
30+
31+
32+
def status_handler(runner_config, data):
33+
plugin_config = get_configuration(runner_config)
34+
if plugin_config['runner_url'] is not None:
35+
status = send_request(plugin_config['runner_url'],
36+
data=data,
37+
headers=plugin_config['runner_headers'],
38+
urlpath=plugin_config['runner_path'])
39+
logger.debug("POST Response {}".format(status))
40+
else:
41+
logger.info("HTTP Plugin Skipped")
42+
43+
44+
def event_handler(runner_config, data):
45+
status_handler(runner_config, data)

0 commit comments

Comments
 (0)