Add http-fileserver role
Role will allow to easily serve static content over http. python simple http server wrapped into systemd unit Change-Id: I7726b973ad77ab3a58819ff48033a74095ed3ea0
This commit is contained in:
parent
3f0f471ed3
commit
c9e3feceae
3
roles/http-fileserver/defaults/main.yml
Normal file
3
roles/http-fileserver/defaults/main.yml
Normal file
@ -0,0 +1,3 @@
|
||||
http_fileserver_serve_dir: /srv/http-server
|
||||
http_fileserver_serve_port: 8099
|
||||
http_server_action: install
|
11
roles/http-fileserver/handlers/main.yml
Normal file
11
roles/http-fileserver/handlers/main.yml
Normal file
@ -0,0 +1,11 @@
|
||||
- name: reload systemd configuration
|
||||
become: yes
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
|
||||
- name: http file server restarted
|
||||
service:
|
||||
name: simple-http-{{ http_fileserver_name | default('default') }}.service
|
||||
state: restarted
|
||||
enabled: true
|
||||
become: true
|
33
roles/http-fileserver/tasks/install.yml
Normal file
33
roles/http-fileserver/tasks/install.yml
Normal file
@ -0,0 +1,33 @@
|
||||
- name: install simplehttpserver package
|
||||
apt:
|
||||
name:
|
||||
- python3
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: set http server systemd unit content
|
||||
set_fact:
|
||||
http_fileserver_unit_content: |
|
||||
[Unit]
|
||||
Description=Simple http server
|
||||
After=syslog.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/python3 -m http.server {{ http_fileserver_serve_port }}
|
||||
StandardOutput=syslog
|
||||
StandardError=syslog
|
||||
WorkingDirectory={{ http_fileserver_serve_dir }}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
- name: Create systemd unit
|
||||
copy:
|
||||
content: "{{ http_fileserver_unit_content }}"
|
||||
dest: /etc/systemd/system/simple-http-{{ http_fileserver_name | default('default') }}.service
|
||||
notify:
|
||||
- reload systemd configuration
|
||||
- http file server restarted
|
||||
become: true
|
||||
|
1
roles/http-fileserver/tasks/main.yml
Normal file
1
roles/http-fileserver/tasks/main.yml
Normal file
@ -0,0 +1 @@
|
||||
- include_tasks: "{{ http_server_action }}.yml"
|
6
roles/http-fileserver/tasks/remove.yml
Normal file
6
roles/http-fileserver/tasks/remove.yml
Normal file
@ -0,0 +1,6 @@
|
||||
- name: ensure http service is stopped
|
||||
service:
|
||||
name: simple-http-{{ http_fileserver_name | default('default') }}.service
|
||||
state: stopped
|
||||
enabled: false
|
||||
become: true
|
30
roles/http-fileserver/tests/main.yml
Normal file
30
roles/http-fileserver/tests/main.yml
Normal file
@ -0,0 +1,30 @@
|
||||
- name: Include test variables.
|
||||
include_vars:
|
||||
file: vars.yml
|
||||
|
||||
- name: ensure serve directory exists
|
||||
file:
|
||||
path: "{{ http_fileserver_serve_dir }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
become: true
|
||||
|
||||
- name: install http-fileserver
|
||||
include_role:
|
||||
name: http-fileserver
|
||||
|
||||
- name: trigger all saved handlers
|
||||
meta: flush_handlers
|
||||
|
||||
- name: copy test file to serve directory
|
||||
become: true
|
||||
copy:
|
||||
content: "{{ http_file_server_test_file_content }}"
|
||||
dest: "{{ http_fileserver_serve_dir }}/{{ http_fileserver_test_file_name }}"
|
||||
register: file_copy_command
|
||||
|
||||
- name: download test file
|
||||
get_url:
|
||||
url: "http://localhost:{{ http_fileserver_serve_port }}/{{ http_fileserver_test_file_name }}"
|
||||
dest: "/tmp/{{ http_fileserver_test_file_name }}"
|
||||
checksum: "sha1:{{ file_copy_command.checksum }}"
|
4
roles/http-fileserver/tests/vars.yml
Normal file
4
roles/http-fileserver/tests/vars.yml
Normal file
@ -0,0 +1,4 @@
|
||||
http_fileserver_serve_dir: /srv/test-dir
|
||||
http_fileserver_serve_port: 8095
|
||||
http_file_server_test_file_content: "something to test"
|
||||
http_fileserver_test_file_name: "test-file"
|
@ -10,6 +10,7 @@
|
||||
- libvirt-domain
|
||||
- redfish-emulator
|
||||
- airship-libvirt-gate
|
||||
- http-fileserver
|
||||
- name: run tests against defined roles
|
||||
include_tasks: "../../roles/{{ role_name }}/tests/main.yml"
|
||||
with_items: "{{ test_subject_roles | default(test_subject_roles_default) }}"
|
||||
|
@ -15,6 +15,14 @@
|
||||
run: tests/ansible/lint.yml
|
||||
nodeset: ubuntu-single-airship
|
||||
|
||||
- job:
|
||||
name: zuul-airship-roles-fileserver
|
||||
run: tests/ansible/role-test-runner.yml
|
||||
vars:
|
||||
test_subject_roles:
|
||||
- http-fileserver
|
||||
nodeset: ubuntu-single-airship
|
||||
|
||||
- job:
|
||||
name: zuul-airship-roles-test-libvirt
|
||||
run: tests/ansible/role-test-runner.yml
|
||||
|
@ -4,8 +4,10 @@
|
||||
- ansible-lint-airship
|
||||
- zuul-airship-roles-test-libvirt
|
||||
- zuul-airship-roles-test-airship-gate
|
||||
- zuul-airship-roles-fileserver
|
||||
gate:
|
||||
jobs:
|
||||
- ansible-lint-airship
|
||||
- zuul-airship-roles-test-libvirt
|
||||
- zuul-airship-roles-test-airship-gate
|
||||
- zuul-airship-roles-fileserver
|
||||
|
Loading…
Reference in New Issue
Block a user