From 77e134d1779a432fbb97628f82f318cfda206aa3 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 16:58:19 +0000 Subject: [PATCH 01/18] Adds action to install platform --- .github/workflows/platform.yml | 50 ++++++++++++++++++++++++++++++++++ meta/galaxy-requirements.yml | 9 ++++++ templates/mt4_install.verb.j2 | 2 +- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/platform.yml create mode 100644 meta/galaxy-requirements.yml diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml new file mode 100644 index 0000000..b64a3cb --- /dev/null +++ b/.github/workflows/platform.yml @@ -0,0 +1,50 @@ +--- +name: Platform + +# yamllint disable-line rule:truthy +on: + pull_request: + paths: + - '.github/workflows/platform.yml' + push: + branches: + - 'master' + - '*dev*' + paths: + - '.github/workflows/platform.yml' + +jobs: + Install-MT4: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Installs platform + uses: dawidd6/action-ansible-playbook@v2 + with: + configuration: | + [defaults] + nocows = false + stdout_callback = yaml + options: | + --connection local + --inventory localhost, + --verbose + playbook: molecule/mt4/converge.yml + requirements: meta/galaxy-requirements.yml + Install-MT5: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Installs platform + uses: dawidd6/action-ansible-playbook@v2 + with: + configuration: | + [defaults] + nocows = false + stdout_callback = yaml + options: | + --connection local + --inventory localhost, + --verbose + playbook: molecule/mt5/converge.yml + requirements: meta/galaxy-requirements.yml diff --git a/meta/galaxy-requirements.yml b/meta/galaxy-requirements.yml new file mode 100644 index 0000000..fcd1bc6 --- /dev/null +++ b/meta/galaxy-requirements.yml @@ -0,0 +1,9 @@ +# A file containing a list of collections to be installed. +# Usage: +# ansible-galaxy install -r galaxy-requirements.yml +--- +roles: + - name: ea31337.metatrader + scm: git + src: https://github.com/EA31337/ansible-role-metatrader.git + version: dev diff --git a/templates/mt4_install.verb.j2 b/templates/mt4_install.verb.j2 index e15606e..2cba693 100644 --- a/templates/mt4_install.verb.j2 +++ b/templates/mt4_install.verb.j2 @@ -11,7 +11,7 @@ load_mt4_install() if w_workaround_wine_bug 7156 "${title} needs wingdings.ttf, installing opensymbol" then - echo w_call opensymbol # @fixme: GH-6 + w_call opensymbol # @fixme: GH-6 fi # Opens a webpage. From 4f3535d980b3b42daeb94c431a794d98d4bb12c5 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 17:14:45 +0000 Subject: [PATCH 02/18] GHA: platform: Adds actions/upload-artifact --- .github/workflows/platform.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index b64a3cb..24ebf16 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -31,6 +31,11 @@ jobs: --verbose playbook: molecule/mt4/converge.yml requirements: meta/galaxy-requirements.yml + - uses: actions/upload-artifact@v4 + with: + name: platform-files + path: ~/.wine/drive_c/Program Files*/*(Meta|MT)* + timeout-minutes: 20 Install-MT5: runs-on: ubuntu-latest steps: @@ -48,3 +53,8 @@ jobs: --verbose playbook: molecule/mt5/converge.yml requirements: meta/galaxy-requirements.yml + - uses: actions/upload-artifact@v4 + with: + name: platform-files + path: ~/.wine/drive_c/Program Files*/*{Meta|MT}* + timeout-minutes: 20 From c19c4c5fe3fcf5577e4d75574b40b8c09b0f47cb Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 17:26:32 +0000 Subject: [PATCH 03/18] Uses multiple items Refs: https://github.com/actions/upload-artifact/issues/331 --- .github/workflows/platform.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index 24ebf16..a215085 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -33,8 +33,10 @@ jobs: requirements: meta/galaxy-requirements.yml - uses: actions/upload-artifact@v4 with: - name: platform-files - path: ~/.wine/drive_c/Program Files*/*(Meta|MT)* + name: platform + path: | + ~/.wine/drive_c/Program Files*/*MT* + ~/.wine/drive_c/Program Files*/*Meta* timeout-minutes: 20 Install-MT5: runs-on: ubuntu-latest @@ -55,6 +57,8 @@ jobs: requirements: meta/galaxy-requirements.yml - uses: actions/upload-artifact@v4 with: - name: platform-files - path: ~/.wine/drive_c/Program Files*/*{Meta|MT}* + name: platform + path: | + ~/.wine/drive_c/Program Files*/*MT* + ~/.wine/drive_c/Program Files*/*Meta* timeout-minutes: 20 From d1e58cabddf74cd85d4bed8992ac7382e5cd7d7e Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 17:34:09 +0000 Subject: [PATCH 04/18] Adds cleanup action --- .github/workflows/platform.yml | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index a215085..26b3574 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -14,7 +14,7 @@ on: - '.github/workflows/platform.yml' jobs: - Install-MT4: + Install-MT4-Linux: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -33,12 +33,12 @@ jobs: requirements: meta/galaxy-requirements.yml - uses: actions/upload-artifact@v4 with: - name: platform + name: platform4 path: | - ~/.wine/drive_c/Program Files*/*MT* - ~/.wine/drive_c/Program Files*/*Meta* + ~/.wine/drive_c/Program Files*/**/*MT* + ~/.wine/drive_c/Program Files*/**/*Meta* timeout-minutes: 20 - Install-MT5: + Install-MT5-Linux: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -57,8 +57,17 @@ jobs: requirements: meta/galaxy-requirements.yml - uses: actions/upload-artifact@v4 with: - name: platform + name: platform5 path: | - ~/.wine/drive_c/Program Files*/*MT* - ~/.wine/drive_c/Program Files*/*Meta* + ~/.wine/drive_c/Program Files*/**/*MT* + ~/.wine/drive_c/Program Files*/**/*Meta* timeout-minutes: 20 + Cleanup-MT-Linux: + needs: + - Install-MT4-Linux + - Install-MT5-Linux + runs-on: ubuntu-latest + steps: + - uses: geekyeggo/delete-artifact@v4 + with: + name: platform* From 90ab0c2ea42817506fdecd08b7948f1d0d96f663 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 17:49:56 +0000 Subject: [PATCH 05/18] GHA: platform: Adds on.workflow_call --- .github/workflows/platform.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index 26b3574..9f9b58d 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -12,6 +12,7 @@ on: - '*dev*' paths: - '.github/workflows/platform.yml' + workflow_call: jobs: Install-MT4-Linux: From b5f35c2c34799b3c62dd90329b3d770223b22757 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 18:02:08 +0000 Subject: [PATCH 06/18] GHA: Adds directory pointing to github.workspace --- .github/workflows/platform.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index 9f9b58d..9882120 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -26,6 +26,7 @@ jobs: [defaults] nocows = false stdout_callback = yaml + directory: ${{ github.workspace }} options: | --connection local --inventory localhost, @@ -50,6 +51,7 @@ jobs: [defaults] nocows = false stdout_callback = yaml + directory: ${{ github.workspace }} options: | --connection local --inventory localhost, From 66a12659ad3c4ba4c2b2ee0cf3859becf696d033 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 18:08:34 +0000 Subject: [PATCH 07/18] GHA: Adds inputs.workdir --- .github/workflows/platform.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index 9882120..eff6eb9 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -13,6 +13,12 @@ on: paths: - '.github/workflows/platform.yml' workflow_call: + inputs: + workdir: + default: "${{ github.workspace }}" + description: 'Working directory' + required: false + type: string jobs: Install-MT4-Linux: @@ -26,7 +32,7 @@ jobs: [defaults] nocows = false stdout_callback = yaml - directory: ${{ github.workspace }} + directory: ${{ inputs.workdir }} options: | --connection local --inventory localhost, @@ -51,7 +57,7 @@ jobs: [defaults] nocows = false stdout_callback = yaml - directory: ${{ github.workspace }} + directory: ${{ inputs.workdir }} options: | --connection local --inventory localhost, From ab692566bec68b996a3a334ece5e6bd7a06f99c5 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 19:58:33 +0000 Subject: [PATCH 08/18] GHA: Improves platform workflow, adds artifact input --- .github/workflows/platform.yml | 59 ++++++++++++++-------------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index eff6eb9..3427f0c 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -1,6 +1,11 @@ --- name: Platform +env: + ARTIFACT_NAME: ${{ inputs.artifact || 'platform' }} + VERSION: ${{ inputs.version || 5 }} + WORKDIR: ${{ inputs.workdir || github.workspace }} + # yamllint disable-line rule:truthy on: pull_request: @@ -14,67 +19,51 @@ on: - '.github/workflows/platform.yml' workflow_call: inputs: + artifact: + default: platform + description: Artifact name + required: false + type: string + version: + default: 5 + description: Version to install + type: number workdir: - default: "${{ github.workspace }}" - description: 'Working directory' + default: ${{ github.workspace }} + description: Working directory required: false type: string jobs: - Install-MT4-Linux: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Installs platform - uses: dawidd6/action-ansible-playbook@v2 - with: - configuration: | - [defaults] - nocows = false - stdout_callback = yaml - directory: ${{ inputs.workdir }} - options: | - --connection local - --inventory localhost, - --verbose - playbook: molecule/mt4/converge.yml - requirements: meta/galaxy-requirements.yml - - uses: actions/upload-artifact@v4 - with: - name: platform4 - path: | - ~/.wine/drive_c/Program Files*/**/*MT* - ~/.wine/drive_c/Program Files*/**/*Meta* - timeout-minutes: 20 - Install-MT5-Linux: + Platform-Linux: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Installs platform + - name: Runs playbook uses: dawidd6/action-ansible-playbook@v2 with: configuration: | [defaults] nocows = false stdout_callback = yaml - directory: ${{ inputs.workdir }} + directory: ${{ env.WORKDIR }} options: | --connection local --inventory localhost, --verbose - playbook: molecule/mt5/converge.yml + playbook: molecule/mt${{ env.VERSION }}/converge.yml requirements: meta/galaxy-requirements.yml - uses: actions/upload-artifact@v4 with: - name: platform5 + name: ${{ env.ARTIFACT_NAME }} path: | ~/.wine/drive_c/Program Files*/**/*MT* ~/.wine/drive_c/Program Files*/**/*Meta* timeout-minutes: 20 - Cleanup-MT-Linux: + Cleanup: + if: ${{ github.event_name != 'workflow_call' }} needs: - - Install-MT4-Linux - - Install-MT5-Linux + - Platform-Linux runs-on: ubuntu-latest steps: - uses: geekyeggo/delete-artifact@v4 From cb17d2da3046fd002bf23d0d48852b8c5baf4041 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 20:37:32 +0000 Subject: [PATCH 09/18] GHA: Adds workdir to outputs --- .github/workflows/platform.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index 3427f0c..f53a93f 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -33,9 +33,16 @@ on: description: Working directory required: false type: string + outputs: + workdir: + description: Working directory + value: ${{ jobs.platform-linux.outputs.workdir }} jobs: - Platform-Linux: + platform-linux: + name: Platform (Linux) + outputs: + workdir: ${{ github.workspace }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -60,10 +67,10 @@ jobs: ~/.wine/drive_c/Program Files*/**/*MT* ~/.wine/drive_c/Program Files*/**/*Meta* timeout-minutes: 20 - Cleanup: + cleanup: if: ${{ github.event_name != 'workflow_call' }} - needs: - - Platform-Linux + name: Clean-up + needs: [platform-linux] runs-on: ubuntu-latest steps: - uses: geekyeggo/delete-artifact@v4 From b2a675dd722abd8e3d30fbee22d9611d53c7181d Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 20:51:06 +0000 Subject: [PATCH 10/18] GHA: Adds inputs.ref --- .github/workflows/platform.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index f53a93f..5ab9aef 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -3,6 +3,8 @@ name: Platform env: ARTIFACT_NAME: ${{ inputs.artifact || 'platform' }} + CHECKOUT_REF: ${{ inputs.ref || 'dev' }} + REPOSITORY: EA31337/ansible-role-metatrader VERSION: ${{ inputs.version || 5 }} WORKDIR: ${{ inputs.workdir || github.workspace }} @@ -24,6 +26,11 @@ on: description: Artifact name required: false type: string + ref: + default: dev + description: The branch, tag or SHA to checkout. + required: false + type: string version: default: 5 description: Version to install @@ -46,6 +53,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + ref: ${{ env.CHECKOUT_REF }} + repository: ${{ env.REPOSITORY }} - name: Runs playbook uses: dawidd6/action-ansible-playbook@v2 with: From a181c0c7fd711c7aeed4535f7db17218133e4526 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 21:30:24 +0000 Subject: [PATCH 11/18] GHA: Adds cleanup_needs input --- .github/workflows/platform.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index 5ab9aef..bacf4ab 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -4,6 +4,7 @@ name: Platform env: ARTIFACT_NAME: ${{ inputs.artifact || 'platform' }} CHECKOUT_REF: ${{ inputs.ref || 'dev' }} + CLEANUP_NEEDS: ${{ inputs.cleanup_needs || 'platform-linux' }} REPOSITORY: EA31337/ansible-role-metatrader VERSION: ${{ inputs.version || 5 }} WORKDIR: ${{ inputs.workdir || github.workspace }} @@ -26,6 +27,11 @@ on: description: Artifact name required: false type: string + cleanup_needs: + default: platform-linux + description: Name of job to wait with clean-up steps + required: false + type: string ref: default: dev description: The branch, tag or SHA to checkout. @@ -78,11 +84,10 @@ jobs: ~/.wine/drive_c/Program Files*/**/*Meta* timeout-minutes: 20 cleanup: - if: ${{ github.event_name != 'workflow_call' }} name: Clean-up - needs: [platform-linux] + needs: ${{ env.CLEANUP_NEEDS }} runs-on: ubuntu-latest steps: - uses: geekyeggo/delete-artifact@v4 with: - name: platform* + name: ${{ env.ARTIFACT_NAME }} From 89277651631dd31ade046e2805f43409ae32fdf8 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 21:31:58 +0000 Subject: [PATCH 12/18] Revert "GHA: Adds cleanup_needs input" This reverts commit a181c0c7fd711c7aeed4535f7db17218133e4526. --- .github/workflows/platform.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index bacf4ab..5ab9aef 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -4,7 +4,6 @@ name: Platform env: ARTIFACT_NAME: ${{ inputs.artifact || 'platform' }} CHECKOUT_REF: ${{ inputs.ref || 'dev' }} - CLEANUP_NEEDS: ${{ inputs.cleanup_needs || 'platform-linux' }} REPOSITORY: EA31337/ansible-role-metatrader VERSION: ${{ inputs.version || 5 }} WORKDIR: ${{ inputs.workdir || github.workspace }} @@ -27,11 +26,6 @@ on: description: Artifact name required: false type: string - cleanup_needs: - default: platform-linux - description: Name of job to wait with clean-up steps - required: false - type: string ref: default: dev description: The branch, tag or SHA to checkout. @@ -84,10 +78,11 @@ jobs: ~/.wine/drive_c/Program Files*/**/*Meta* timeout-minutes: 20 cleanup: + if: ${{ github.event_name != 'workflow_call' }} name: Clean-up - needs: ${{ env.CLEANUP_NEEDS }} + needs: [platform-linux] runs-on: ubuntu-latest steps: - uses: geekyeggo/delete-artifact@v4 with: - name: ${{ env.ARTIFACT_NAME }} + name: platform* From 9dc60fa90f04fb42807edb39f8110736ad6e853a Mon Sep 17 00:00:00 2001 From: kenorb Date: Sun, 11 Feb 2024 21:57:07 +0000 Subject: [PATCH 13/18] GHA: Corrects artifact name for delete-artifact job --- .github/workflows/platform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index 5ab9aef..3dd2956 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -85,4 +85,4 @@ jobs: steps: - uses: geekyeggo/delete-artifact@v4 with: - name: platform* + name: ${{ env.ARTIFACT_NAME }} From 6ab4115a89798c099258722def56e42ac0ab994d Mon Sep 17 00:00:00 2001 From: kenorb Date: Tue, 13 Feb 2024 01:35:21 +0000 Subject: [PATCH 14/18] GHA: Fixes platform workflow --- .github/workflows/platform.yml | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index 3dd2956..33faa33 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -1,12 +1,12 @@ --- -name: Platform +name: Platform (Linux) env: ARTIFACT_NAME: ${{ inputs.artifact || 'platform' }} CHECKOUT_REF: ${{ inputs.ref || 'dev' }} + CLEANUP: ${{ inputs.cleanup || true }} REPOSITORY: EA31337/ansible-role-metatrader VERSION: ${{ inputs.version || 5 }} - WORKDIR: ${{ inputs.workdir || github.workspace }} # yamllint disable-line rule:truthy on: @@ -26,6 +26,11 @@ on: description: Artifact name required: false type: string + cleanup: + default: false + description: Whether to run clean-up job + required: false + type: boolean ref: default: dev description: The branch, tag or SHA to checkout. @@ -35,19 +40,10 @@ on: default: 5 description: Version to install type: number - workdir: - default: ${{ github.workspace }} - description: Working directory - required: false - type: string - outputs: - workdir: - description: Working directory - value: ${{ jobs.platform-linux.outputs.workdir }} jobs: platform-linux: - name: Platform (Linux) + name: Platform outputs: workdir: ${{ github.workspace }} runs-on: ubuntu-latest @@ -78,11 +74,11 @@ jobs: ~/.wine/drive_c/Program Files*/**/*Meta* timeout-minutes: 20 cleanup: - if: ${{ github.event_name != 'workflow_call' }} name: Clean-up needs: [platform-linux] runs-on: ubuntu-latest steps: - uses: geekyeggo/delete-artifact@v4 + if: env.CLEANUP && github.repository == env.REPOSITORY with: name: ${{ env.ARTIFACT_NAME }} From db60f10d43246186350316d94b79df190b40bc4d Mon Sep 17 00:00:00 2001 From: kenorb Date: Fri, 23 Feb 2024 00:37:19 +0000 Subject: [PATCH 15/18] Uses import_role instead of include_role --- molecule/default/converge.yml | 2 +- molecule/mt4/converge.yml | 2 +- molecule/mt5/converge.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 61de970..237a62f 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -3,7 +3,7 @@ hosts: all tasks: - name: Include main role - ansible.builtin.include_role: + ansible.builtin.import_role: name: ea31337.metatrader vars: # @fixme: https://github.com/Winetricks/winetricks/issues/2119 diff --git a/molecule/mt4/converge.yml b/molecule/mt4/converge.yml index b1b770d..2ad96ae 100644 --- a/molecule/mt4/converge.yml +++ b/molecule/mt4/converge.yml @@ -3,7 +3,7 @@ hosts: all tasks: - name: Include main role - ansible.builtin.include_role: + ansible.builtin.import_role: name: ea31337.metatrader vars: metatrader_setup_url: | diff --git a/molecule/mt5/converge.yml b/molecule/mt5/converge.yml index eb8f079..12db19f 100644 --- a/molecule/mt5/converge.yml +++ b/molecule/mt5/converge.yml @@ -3,7 +3,7 @@ hosts: all tasks: - name: Include main role - ansible.builtin.include_role: + ansible.builtin.import_role: name: ea31337.metatrader vars: metatrader_version: 5 From 6f785e7cb9c15395ed820f886cc056e19fe75326 Mon Sep 17 00:00:00 2001 From: kenorb Date: Fri, 23 Feb 2024 00:37:29 +0000 Subject: [PATCH 16/18] Stores platform paths as facts --- tasks/verify.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tasks/verify.yml b/tasks/verify.yml index 58bf970..45e3150 100644 --- a/tasks/verify.yml +++ b/tasks/verify.yml @@ -22,3 +22,16 @@ recurse: true register: find_mte_res when: ansible_os_family != "Windows" +- name: Stores platform paths as facts + block: + - name: Sets fact + ansible.builtin.set_fact: + metatrader: >- + { '{{ metatrader_version | int }}': {'path': '{{ find_mt_res.files[0].path | dirname }}'}} + when: + - find_mt_res is defined + - find_mt_res.files | length > 0 + - metatrader_version is defined + - name: Prints current facts + ansible.builtin.debug: + var: hostvars[inventory_hostname]['metatrader'] From 074dd18d6eb58157716033e610a6d10b13f9f558 Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 24 Feb 2024 16:09:54 +0000 Subject: [PATCH 17/18] Improves fact logic --- tasks/main.yml | 82 +++++++++++++++++++++++++++++++++++++----------- tasks/verify.yml | 13 -------- 2 files changed, 63 insertions(+), 32 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index d054651..5591fe0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,31 +1,44 @@ --- -- name: Validates variables - ansible.builtin.assert: - that: - - metatrader_setup_url | length > 0 -- name: Checks if platform is already installed - register: file_mt_installed_exists +- name: Collects local facts + ansible.builtin.setup: + filter: + - ansible_local + when: false +- name: Checks if platform is already exist ansible.builtin.stat: - path: ~/.wine/.installed-mt{{ metatrader_version }} + path: "{{ ansible_local['metatrader'][metatrader_version | string].path }}" + register: stat_mt + when: ansible_local['metatrader'] is defined +- name: Ensures platform is installed when: - - ansible_os_family != "Windows" -- name: Ensures Curl is present - ansible.builtin.package: - name: curl - state: present - when: - - ansible_os_family != "Windows" - - not file_mt_installed_exists.stat.exists -- name: Installs MetaTrader (via Winetricks) - when: - - ansible_os_family != "Windows" - - not file_mt_installed_exists.stat.exists + - ansible_local['metatrader'] is not defined + - ansible_os_family != "Windows" # gather_facts is required. + - (stat_mt.stat is not defined) or (not stat_mt.stat.exists) block: + - name: Validates variables + ansible.builtin.assert: + that: + - metatrader_setup_url | length > 0 + - name: Checks if platform is already installed + register: file_mt_installed_exists + ansible.builtin.stat: + path: ~/.wine/.installed-mt{{ metatrader_version }} + when: + - ansible_os_family != "Windows" + - name: Ensures Curl is present + ansible.builtin.package: + name: curl + state: present + when: + - ansible_os_family != "Windows" + - not file_mt_installed_exists.stat.exists - name: Ensures verb installation file is present ansible.builtin.template: src: mt{{ metatrader_version }}_install.verb.j2 dest: /tmp/mt{{ metatrader_version }}_install.verb mode: "0640" + when: + - not file_mt_installed_exists.stat.exists - name: Ensures MetaTrader is installed (via verb file) ansible.builtin.shell: # noqa command-instead-of-shell @@ -37,6 +50,8 @@ creates: ~/.wine/.installed-mt{{ metatrader_version }} args: executable: /bin/bash + when: + - not file_mt_installed_exists.stat.exists - name: Ensures verb installation file is absent ansible.builtin.file: path: /tmp/mt{{ metatrader_version }}_install.verb @@ -45,3 +60,32 @@ ansible.builtin.include_tasks: verify.yml tags: - metatrader_verify +- name: Stores platform paths as facts + become: true + when: + - ansible_local['metatrader'] is not defined + block: + - name: Sets fact + ansible.builtin.set_fact: + cacheable: true + metatrader: >- + { + '{{ metatrader_version | int }}': + { + 'path': '{{ find_mt_res.files[0].path | dirname }}' + } + } + when: + - find_mt_res is defined + - find_mt_res.files | length > 0 + - metatrader_version is defined + - name: Ensures that Ansible local facts directory exists + ansible.builtin.file: + path: /etc/ansible/facts.d + state: directory + mode: '0755' + - name: Saves role's facts + ansible.builtin.copy: + content: "{{ ansible_facts['metatrader'] }}" + dest: /etc/ansible/facts.d/metatrader.fact + mode: "0644" diff --git a/tasks/verify.yml b/tasks/verify.yml index 45e3150..58bf970 100644 --- a/tasks/verify.yml +++ b/tasks/verify.yml @@ -22,16 +22,3 @@ recurse: true register: find_mte_res when: ansible_os_family != "Windows" -- name: Stores platform paths as facts - block: - - name: Sets fact - ansible.builtin.set_fact: - metatrader: >- - { '{{ metatrader_version | int }}': {'path': '{{ find_mt_res.files[0].path | dirname }}'}} - when: - - find_mt_res is defined - - find_mt_res.files | length > 0 - - metatrader_version is defined - - name: Prints current facts - ansible.builtin.debug: - var: hostvars[inventory_hostname]['metatrader'] From a8e57fba7176fdbe6220670f0e18bc74845ff72f Mon Sep 17 00:00:00 2001 From: kenorb Date: Sat, 24 Feb 2024 23:02:33 +0000 Subject: [PATCH 18/18] Improves fact conditions Sets gather_facts to true --- molecule/default/converge.yml | 1 + tasks/main.yml | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 237a62f..1a46094 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -1,6 +1,7 @@ --- - name: Converge hosts: all + gather_facts: true tasks: - name: Include main role ansible.builtin.import_role: diff --git a/tasks/main.yml b/tasks/main.yml index 5591fe0..31af17d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -60,10 +60,13 @@ ansible.builtin.include_tasks: verify.yml tags: - metatrader_verify -- name: Stores platform paths as facts +- name: Saves platform facts become: true when: - - ansible_local['metatrader'] is not defined + - >- + ansible_local['metatrader'] is not defined + or (find_mt_res.files[0].path | dirname) + != ansible_local['metatrader'][metatrader_version | string].path block: - name: Sets fact ansible.builtin.set_fact: