Skip to content

Commit

Permalink
Improves fact logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Feb 24, 2024
1 parent 6f785e7 commit 5d463ef
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 33 deletions.
82 changes: 62 additions & 20 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
---
- 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 }}
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
path: "{{ ansible_local['metatrader'][metatrader_version | string].path }}"
register: stat_mt
when: ansible_local['metatrader'] is defined
- name: Ensures platform is installed

Check failure on line 12 in tasks/main.yml

View workflow job for this annotation

GitHub Actions / Pre-commit

key-order[task]

You can improve the task key order to: name, when, block
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
Expand All @@ -37,11 +46,44 @@
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
state: absent
when:
- ansible_local['metatrader'] is not defined
- ansible_os_family != "Windows" # gather_facts is required.
- not stat_mt.stat.exists
- name: Verifies
ansible.builtin.include_tasks: verify.yml
tags:
- metatrader_verify
- name: Stores platform paths as facts

Check failure on line 63 in tasks/main.yml

View workflow job for this annotation

GitHub Actions / Pre-commit

key-order[task]

You can improve the task key order to: name, when, block
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

Check failure on line 84 in tasks/main.yml

View workflow job for this annotation

GitHub Actions / Pre-commit

risky-file-permissions

File permissions unset or incorrect.
ansible.builtin.copy:
content: "{{ ansible_facts['metatrader'] }}"
dest: /etc/ansible/facts.d/metatrader.fact
when:
- ansible_local['metatrader'] is not defined
13 changes: 0 additions & 13 deletions tasks/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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']

0 comments on commit 5d463ef

Please sign in to comment.