Skip to content

Commit

Permalink
fix: improve error handling and task idempotence on binary check
Browse files Browse the repository at this point in the history
  • Loading branch information
trfore committed Apr 1, 2024
1 parent 29c9f35 commit ed26b50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ scenario:
- syntax
- create
- converge
# - idempotence
- idempotence
- verify
- destroy
16 changes: 7 additions & 9 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,30 @@
tags: jsvc

- name: Check for jsvc binary
ansible.builtin.command: which jsvc
ignore_errors: true
ansible.builtin.stat:
path: /usr/bin/jsvc
register: jsvc_binary
changed_when: jsvc_binary.rc
tags: jsvc

- name: Error when jsvc is missing
ansible.builtin.fail:
msg: 'Error: jsvc is not present, Omada SDN requires jsvc'
when:
- "'jsvc' not in ansible_facts.packages"
- jsvc_binary.rc != 0
- not jsvc_binary.stat.exists
tags: jsvc

- name: Check for omada binary
ansible.builtin.command: which tpeap
ignore_errors: true
ansible.builtin.stat:
path: /usr/bin/tpeap
register: omada_binary
changed_when: omada_binary.rc

- name: Create a temporary directory for omada tar file
ansible.builtin.file:
path: '{{ omada_tar_dir }}/{{ omada_tar_folder }}'
state: directory
mode: '0775'
when: omada_binary.rc != 0
when: not omada_binary.stat.exists
register: omada_temp_dir

- name: Download and extract omada software
Expand All @@ -71,7 +69,7 @@
extra_opts:
- --strip-components=1
register: omada_tar
when: omada_binary.rc != 0
when: not omada_binary.stat.exists

- name: Run omada install script
become: true
Expand Down

0 comments on commit ed26b50

Please sign in to comment.