github.com/crowdsecurity/crowdsec@v1.6.1/test/ansible/install_binary_package.yml (about)

     1  # vim: set ft=yaml.ansible:
     2  ---
     3  
     4  - name: "Install and set up binary crowdsec package..."
     5    hosts: all
     6    gather_facts: true
     7    tasks:
     8  
     9      - name: "Hardcode master branch for the hub, temporary override before install (config.yaml.local)"
    10        become: true
    11        block:
    12          - name: "Create /etc/crowdsec"
    13            ansible.builtin.file:
    14              path: "/etc/crowdsec"
    15              state: directory
    16              mode: 0o0755
    17          - name: "Create /etc/crowdsec/config.yaml.local"
    18            ansible.builtin.copy:
    19              dest: "/etc/crowdsec/config.yaml.local"
    20              content: "{{ config_yaml_local | to_nice_yaml }}"
    21              mode: 0o600
    22            vars:
    23              config_yaml_local:
    24                cscli:
    25                  hub_branch: master
    26        when:
    27          - (package_version_deb | length > 0) or
    28            (package_version_rpm | length > 0) or
    29            (package_file | length > 0) or
    30            (package_dir | length > 0)
    31  
    32      - name: "Install crowdsec binaries from a binary repository"
    33        ansible.builtin.include_role:
    34          name: crowdsecurity.testing.install_package_from_repo
    35        when: (package_version_deb | length > 0) or
    36              (package_version_rpm | length > 0)
    37  
    38      - name: "Install crowdsec binaries from a package file"
    39        ansible.builtin.include_role:
    40          name: crowdsecurity.testing.install_package_from_file
    41        when: package_file | length > 0
    42  
    43      - name: "Install crowdsec binaries from a package directory"
    44        ansible.builtin.include_role:
    45          name: crowdsecurity.testing.install_package_from_pkgdir
    46        when: package_dir | length > 0
    47  
    48      - name: "Hardcode master branch for the hub, for real this time"
    49        become: true
    50        block:
    51          - name: "Read config.yaml"
    52            ansible.builtin.slurp:
    53              path: "/etc/crowdsec/config.yaml"
    54            register: config_yaml
    55          - name: "Create fact from config.yaml"
    56            ansible.builtin.set_fact:
    57              config_data: "{{ config_yaml['content'] | b64decode | from_yaml }}"
    58          - name: "Patch dictionary"
    59            ansible.builtin.set_fact:
    60              config_data: "{{ config_data | combine(config_patch, recursive=True) }}"
    61            vars:
    62              config_patch:
    63                cscli:
    64                  hub_branch: master
    65          - name: "Write patched config.yaml"
    66            ansible.builtin.copy:
    67              content: '{{ config_data | to_nice_yaml }}'
    68              dest: "/etc/crowdsec/config.yaml"
    69              # preserve mode to be able to test permissions from package
    70              mode: preserve
    71          - name: "Remove config.yaml.local"
    72            ansible.builtin.file:
    73              path: "/etc/crowdsec/config.yaml.local"
    74              state: absent
    75        when:
    76          - (package_version_deb | length > 0) or
    77            (package_version_rpm | length > 0) or
    78            (package_file | length > 0) or
    79            (package_dir | length > 0)
    80  
    81      # this is required to avoid fatal errors in case systemctl is not working
    82      # (which happens on some aws instances)
    83      - name: "Override acquis.yaml for package testing"
    84        become: true
    85        ansible.builtin.copy:
    86          dest: "/etc/crowdsec/acquis.yaml"
    87          content: "{{ acquis_yaml | to_nice_yaml }}"
    88          mode: preserve
    89        vars:
    90          acquis_yaml:
    91            filenames:
    92              - /tmp/should-not-exist.log
    93            labels:
    94              type: syslog
    95              force_inotify: true
    96        when:
    97          - (package_version_deb | length > 0) or
    98            (package_version_rpm | length > 0) or
    99            (package_file | length > 0) or
   100            (package_dir | length > 0)
   101  
   102    vars:
   103      package_version_deb: >-
   104        {{ lookup('ansible.builtin.env', 'TEST_PACKAGE_VERSION_DEB') }}
   105      package_version_rpm: >-
   106        {{ lookup('ansible.builtin.env', 'TEST_PACKAGE_VERSION_RPM') }}
   107      package_file: >-
   108        {{ lookup('ansible.builtin.env', 'TEST_PACKAGE_FILE') }}
   109      package_dir: >-
   110        {{ lookup('ansible.builtin.env', 'TEST_PACKAGE_DIR') }}
   111      binary_package_name: >-
   112        crowdsec