mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 22:00:22 -07:00
new module nomad_job & nomad_job_info (#867)
* nomad_job module * Delete nomad_job.py * new module nomad_job * fix symlink * disable test with centos6 , not supported * fix centos unsupported * fix * requested changes doc * disable freebsd ci * requested change docs + check_mode * lint * fix syntax * update docs * doc fix Co-authored-by: Felix Fontein <felix@fontein.de> * Update nomad_job.py fix docs + ssl true default * Update nomad_job.yml disable ssl ci * nomad_job_info * Update nomad_job_info.py fix token nomad job info * Update nomad_job.py idempotence + check_mode plan result * Update nomad_job.py fail if no id with json content * Update nomad_job.yml ci idempotence + check_mode , nomad_job and nomad_job_info * Update nomad_job.yml fix ci * Update main.yml add kill nomad ci * Update main.yml always kill * fix check mode delete job * ci with delete and check_mode * lint * force start in first deploy * 12.4 nomad * fix version nomad * fix ci assert * fix ci * fix ci * lint * fix version job id None, import os unused * lint job_info * Update aliases * docs frag + info refacto * lint lint * ci * jmespath * fix ci Co-authored-by: FERREIRA Christophe <christophe.ferreira@cnaf.fr> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
b5b5410575
commit
b2e075e6d3
10 changed files with 1255 additions and 0 deletions
106
tests/integration/targets/nomad/tasks/main.yml
Normal file
106
tests/integration/targets/nomad/tasks/main.yml
Normal file
|
@ -0,0 +1,106 @@
|
|||
- name: Skip unsupported platforms
|
||||
meta: end_play
|
||||
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version is not version('7', '>=')
|
||||
|
||||
- name: Install Nomad and test
|
||||
vars:
|
||||
nomad_version: 0.12.4
|
||||
nomad_uri: https://releases.hashicorp.com/nomad/{{ nomad_version }}/nomad_{{ nomad_version }}_{{ ansible_system | lower }}_{{ nomad_arch }}.zip
|
||||
nomad_cmd: '{{ output_dir }}/nomad'
|
||||
block:
|
||||
|
||||
- name: register pyOpenSSL version
|
||||
command: '{{ ansible_python_interpreter }} -c ''import OpenSSL; print(OpenSSL.__version__)'''
|
||||
register: pyopenssl_version
|
||||
|
||||
- name: Install requests<2.20 (CentOS/RHEL 6)
|
||||
pip:
|
||||
name: requests<2.20
|
||||
register: result
|
||||
until: result is success
|
||||
when: ansible_distribution_file_variety|default() == 'RedHat' and ansible_distribution_major_version is version('6', '<=')
|
||||
|
||||
- name: Install python-nomad
|
||||
pip:
|
||||
name: python-nomad
|
||||
register: result
|
||||
until: result is success
|
||||
|
||||
- name: Install jmespath
|
||||
pip:
|
||||
name: jmespath
|
||||
register: result
|
||||
until: result is success
|
||||
|
||||
- when: pyopenssl_version.stdout is version('0.15', '>=')
|
||||
block:
|
||||
- name: Generate privatekey
|
||||
community.crypto.openssl_privatekey:
|
||||
path: '{{ output_dir }}/privatekey.pem'
|
||||
|
||||
- name: Generate CSR
|
||||
community.crypto.openssl_csr:
|
||||
path: '{{ output_dir }}/csr.csr'
|
||||
privatekey_path: '{{ output_dir }}/privatekey.pem'
|
||||
subject:
|
||||
commonName: localhost
|
||||
|
||||
- name: Generate selfsigned certificate
|
||||
register: selfsigned_certificate
|
||||
community.crypto.openssl_certificate:
|
||||
path: '{{ output_dir }}/cert.pem'
|
||||
csr_path: '{{ output_dir }}/csr.csr'
|
||||
privatekey_path: '{{ output_dir }}/privatekey.pem'
|
||||
provider: selfsigned
|
||||
selfsigned_digest: sha256
|
||||
|
||||
- name: Install unzip
|
||||
package:
|
||||
name: unzip
|
||||
register: result
|
||||
until: result is success
|
||||
when: ansible_distribution != "MacOSX"
|
||||
|
||||
- assert:
|
||||
that: ansible_architecture in ['i386', 'x86_64', 'amd64']
|
||||
|
||||
- set_fact:
|
||||
nomad_arch: '386'
|
||||
when: ansible_architecture == 'i386'
|
||||
|
||||
- set_fact:
|
||||
nomad_arch: amd64
|
||||
when: ansible_architecture in ['x86_64', 'amd64']
|
||||
|
||||
- name: Download nomad binary
|
||||
unarchive:
|
||||
src: '{{ nomad_uri }}'
|
||||
dest: '{{ output_dir }}'
|
||||
remote_src: true
|
||||
register: result
|
||||
until: result is success
|
||||
|
||||
- vars:
|
||||
remote_dir: '{{ echo_output_dir.stdout }}'
|
||||
block:
|
||||
|
||||
- command: echo {{ output_dir }}
|
||||
register: echo_output_dir
|
||||
|
||||
- name: Run tests integration
|
||||
block:
|
||||
- name: Start nomad (dev mode enabled)
|
||||
shell: nohup {{ nomad_cmd }} agent -dev </dev/null >/dev/null 2>&1 &
|
||||
|
||||
- name: wait nomad up
|
||||
wait_for:
|
||||
host: localhost
|
||||
port: 4646
|
||||
delay: 10
|
||||
timeout: 60
|
||||
|
||||
- import_tasks: nomad_job.yml
|
||||
always:
|
||||
|
||||
- name: kill nomad
|
||||
shell: pkill nomad
|
90
tests/integration/targets/nomad/tasks/nomad_job.yml
Normal file
90
tests/integration/targets/nomad/tasks/nomad_job.yml
Normal file
|
@ -0,0 +1,90 @@
|
|||
---
|
||||
|
||||
- name: run check deploy nomad job
|
||||
nomad_job:
|
||||
host: localhost
|
||||
state: present
|
||||
use_ssl: false
|
||||
content: "{{ lookup('file', 'job.hcl') }}"
|
||||
register: job_check_deployed
|
||||
check_mode: true
|
||||
|
||||
- name: run create nomad job
|
||||
nomad_job:
|
||||
host: localhost
|
||||
state: present
|
||||
use_ssl: false
|
||||
content: "{{ lookup('file', 'job.hcl') }}"
|
||||
force_start: true
|
||||
register: job_deployed
|
||||
|
||||
- name: get nomad job deployed
|
||||
nomad_job_info:
|
||||
host: localhost
|
||||
use_ssl: false
|
||||
name: example
|
||||
register: get_nomad_job
|
||||
|
||||
- name: get list of nomad jobs
|
||||
nomad_job_info:
|
||||
host: localhost
|
||||
use_ssl: false
|
||||
register: list_nomad_jobs
|
||||
|
||||
- name: assert job is deployed and tasks is changed
|
||||
assert:
|
||||
that:
|
||||
- job_check_deployed is changed
|
||||
- job_deployed is changed
|
||||
- get_nomad_job.result[0].ID == "example"
|
||||
- list_nomad_jobs.result | length == 1
|
||||
|
||||
- name: run check deploy job idempotence
|
||||
nomad_job:
|
||||
host: localhost
|
||||
state: present
|
||||
use_ssl: false
|
||||
content: "{{ lookup('file', 'job.hcl') }}"
|
||||
register: job_check_deployed_idempotence
|
||||
check_mode: true
|
||||
|
||||
- name: run create nomad job idempotence
|
||||
nomad_job:
|
||||
host: localhost
|
||||
state: present
|
||||
use_ssl: false
|
||||
content: "{{ lookup('file', 'job.hcl') }}"
|
||||
register: job_deployed_idempotence
|
||||
|
||||
- name: run check delete nomad job
|
||||
nomad_job:
|
||||
host: localhost
|
||||
state: absent
|
||||
use_ssl: false
|
||||
content: "{{ lookup('file', 'job.hcl') }}"
|
||||
register: job_deleted_check
|
||||
check_mode: true
|
||||
|
||||
- name: run delete nomad job
|
||||
nomad_job:
|
||||
host: localhost
|
||||
state: absent
|
||||
use_ssl: false
|
||||
content: "{{ lookup('file', 'job.hcl') }}"
|
||||
register: job_deleted
|
||||
|
||||
- name: get job deleted
|
||||
nomad_job_info:
|
||||
host: localhost
|
||||
use_ssl: false
|
||||
name: example
|
||||
register: get_job_delete
|
||||
|
||||
- name: assert idempotence
|
||||
assert:
|
||||
that:
|
||||
- job_check_deployed_idempotence is not changed
|
||||
- job_deployed_idempotence is not changed
|
||||
- job_deleted_check is changed
|
||||
- job_deleted is changed
|
||||
- get_job_delete.result[0].Stop
|
Loading…
Add table
Add a link
Reference in a new issue