mirror of https://github.com/ansible/ansible.git
Remove tests for ansible-runner (#82571)
parent
a452c53375
commit
eb44c77968
@ -1,4 +0,0 @@
|
|||||||
shippable/posix/group5
|
|
||||||
context/controller
|
|
||||||
skip/macos
|
|
||||||
skip/freebsd
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import json
|
|
||||||
import sys
|
|
||||||
import ansible_runner
|
|
||||||
|
|
||||||
# the first positional arg should be where the artifacts live
|
|
||||||
output_dir = sys.argv[1]
|
|
||||||
|
|
||||||
# this calls a single module directly, aka "adhoc" mode
|
|
||||||
r = ansible_runner.run(
|
|
||||||
private_data_dir=output_dir,
|
|
||||||
host_pattern='localhost',
|
|
||||||
module='shell',
|
|
||||||
module_args='whoami'
|
|
||||||
)
|
|
||||||
|
|
||||||
data = {
|
|
||||||
'rc': r.rc,
|
|
||||||
'status': r.status,
|
|
||||||
'events': [x['event'] for x in r.events],
|
|
||||||
'stats': r.stats
|
|
||||||
}
|
|
||||||
|
|
||||||
# insert this header for the flask controller
|
|
||||||
print('#STARTJSON')
|
|
||||||
json.dump(data, sys.stdout)
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import ansible_runner
|
|
||||||
|
|
||||||
|
|
||||||
PLAYBOOK = '''
|
|
||||||
- hosts: localhost
|
|
||||||
gather_facts: False
|
|
||||||
tasks:
|
|
||||||
- set_fact:
|
|
||||||
foo: bar
|
|
||||||
'''
|
|
||||||
|
|
||||||
# the first positional arg should be where the artifacts live
|
|
||||||
output_dir = sys.argv[1]
|
|
||||||
|
|
||||||
invdir = os.path.join(output_dir, 'inventory')
|
|
||||||
if not os.path.isdir(invdir):
|
|
||||||
os.makedirs(invdir)
|
|
||||||
with open(os.path.join(invdir, 'hosts'), 'w') as f:
|
|
||||||
f.write('localhost\n')
|
|
||||||
pbfile = os.path.join(output_dir, 'test.yml')
|
|
||||||
with open(pbfile, 'w') as f:
|
|
||||||
f.write(PLAYBOOK)
|
|
||||||
|
|
||||||
r = ansible_runner.run(private_data_dir=output_dir, playbook='test.yml')
|
|
||||||
|
|
||||||
data = {
|
|
||||||
'rc': r.rc,
|
|
||||||
'status': r.status,
|
|
||||||
'events': [x['event'] for x in r.events],
|
|
||||||
'stats': r.stats
|
|
||||||
}
|
|
||||||
|
|
||||||
# insert this header for the flask controller
|
|
||||||
print('#STARTJSON')
|
|
||||||
json.dump(data, sys.stdout)
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
|
|
||||||
import re
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
def parse_json(value):
|
|
||||||
return json.dumps(json.loads(re.sub('^.*\n#STARTJSON\n', '', value, flags=re.DOTALL)), indent=4, sort_keys=True)
|
|
||||||
|
|
||||||
|
|
||||||
class FilterModule(object):
|
|
||||||
def filters(self):
|
|
||||||
return {
|
|
||||||
'parse_json': parse_json,
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
# no hosts required, test only requires implicit localhost
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -eux
|
|
||||||
|
|
||||||
source virtualenv.sh
|
|
||||||
|
|
||||||
ANSIBLE_ROLES_PATH=../ ansible-playbook test.yml -i inventory "$@"
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
- name: execute the script
|
|
||||||
command: "'{{ ansible_python_interpreter }}' '{{ role_path }}/files/adhoc_example1.py' '{{ lookup('env', 'OUTPUT_DIR') }}'"
|
|
||||||
register: script
|
|
||||||
|
|
||||||
- name: parse script output
|
|
||||||
# work around for ansible-runner showing ansible warnings on stdout
|
|
||||||
set_fact:
|
|
||||||
adexec1_json: "{{ script.stdout | parse_json }}"
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- "adexec1_json.rc == 0"
|
|
||||||
- "adexec1_json.events|length == 4"
|
|
||||||
- "'localhost' in adexec1_json.stats.ok"
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
- block:
|
|
||||||
- include_tasks: setup.yml
|
|
||||||
- include_tasks: adhoc_example1.yml
|
|
||||||
- include_tasks: playbook_example1.yml
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
- name: execute the script
|
|
||||||
command: "'{{ ansible_python_interpreter }}' '{{ role_path }}/files/playbook_example1.py' '{{ lookup('env', 'OUTPUT_DIR') }}'"
|
|
||||||
register: script
|
|
||||||
|
|
||||||
- name: parse script output
|
|
||||||
# work around for ansible-runner showing ansible warnings on stdout
|
|
||||||
set_fact:
|
|
||||||
pbexec_json: "{{ script.stdout | parse_json }}"
|
|
||||||
expected_events:
|
|
||||||
- playbook_on_start
|
|
||||||
- playbook_on_play_start
|
|
||||||
- playbook_on_task_start
|
|
||||||
- runner_on_start
|
|
||||||
- runner_on_ok
|
|
||||||
- playbook_on_stats
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- "pbexec_json.rc == 0"
|
|
||||||
- "pbexec_json.events == expected_events"
|
|
||||||
- "'localhost' in pbexec_json.stats.ok"
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
- name: Install ansible-runner
|
|
||||||
pip:
|
|
||||||
name: ansible-runner
|
|
||||||
version: 2.2.0
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
- hosts: localhost
|
|
||||||
roles:
|
|
||||||
- ansible-runner
|
|
||||||
Loading…
Reference in New Issue