Snippets

Avantra Dev Team Install the Avantra Agent using an Ansible Playbook

Created by Heiko Mannherz last modified
# NOTE:
# This is an example ansible playbook demonstrating how to install Java
# and the Avantra Agent on Linux and Windows. The purpose ist to illustrate
# the tasks all in one file. It is by no means a good way to design an
# ansible playbook.
#
- name: Install Java 8 JRE and Avantra Agent
  hosts: all
  vars:
    # Adapt this value to your Avantra Server, if you have uploaded the agent
    # packages. Or see the comments below how to use direct download links.
    - master_host: your.avantra.server
    # Adapt to the agent version
    - agent_version: 20.5.5
    - agent_dir: /opt/avantra
    - agent_win_dir: ansible_env['ProgramFiles']\avantra
    - agent_user: avantra
    - create_user: true
    - agent_service: avantra-agent

  tasks:
  - name: Install Java 8 on SUSE
    become: true
    package: >
      name=java-1_8_0-openjdk
      state=latest
    when: ansible_os_family == 'Suse'

  - name: Install Java 8 on RedHat
    become: true
    package: >
      name=java-1.8.0-openjdk
      state=latest
    when: ansible_os_family == 'RedHat'

  - name: Install AdoptOpenJdk Java 8 on Windows
    when: ansible_os_family == 'Windows'
    block:
      - name: Get AdoptOpenJDK release info
        win_uri:
          url: "https://api.adoptopenjdk.net/v2/info/releases/openjdk8\
            ?openjdk_impl=hotspot&os=windows&arch=x64&release=latest\
            &type=jre&heap_size=normal"
          return_content: true
          follow_redirects: all
        register: release_info
      - name: Find installer url
        set_fact:
          release_url: >-
            {{
              (release_info.content | from_json).binaries | map(attribute='installer_link') | list +
              (release_info.content | from_json).binaries | map(attribute='installer_name') | list
            }}
      - name: 'Download artifact {{ release_url[1] }}'
        win_get_url:
          url: '{{ release_url[0] }}'
          dest: '%TEMP%'
          force: true
        register: file_downloaded
        retries: 20
        delay: 5
        until: file_downloaded is succeeded
      - name: Install from remote
        win_package:
          path: '{{ file_downloaded.dest }}'
          state: present

  - name: Create user and directory on Linux
    when: ansible_system == 'Linux'
    block:
    - name: Create User
      become: true
      when: create_user
      user:
        name: "{{ agent_user }}"
        state: present
    - name: Create directory
      become: true
      file:
        path: "{{ agent_dir }}"
        state: directory
        owner: "{{ agent_user }}"
        group: "{{ agent_user }}"
        mode: 0755

  - name: Download and Install Avantra Agent on Linux
    when: ansible_system == 'Linux'
    block:
    - name: Download Agent
      get_url:
        # NOTE: You can also head to downloads.avantra.com, generate a direct
        # download link, and use it here. Keep in mind that these generated
        # links expire after 12 hours.
        url: http://{{ master_host}}:9050/AgentUpdate/agent-{{ agent_version }}.bin
        dest: /tmp
        mode: '0755'
    - name: Install Agent
      command: /tmp/agent-{{ agent_version }}.bin -- --silent --start=no
      become: true
      become_user: "{{ agent_user }}"
      args:
        chdir: "{{ agent_dir }}"
    - name: Create Systemd Service file
      become: true
      copy:
        dest: /etc/systemd/system/{{ agent_service }}.service
        content: |
          [Unit]
          Description=Avantra Agent
          After=network.target

          [Service]
          ExecStart={{ agent_dir }}/agent/rc.agent start
          ExecStop={{ agent_dir }}/agent/rc.agent stop
          User={{ agent_user }}
          Type=forking
          KillMode=process
          PIDFile={{ agent_dir }}/agent/log/agent.pid

          [Install]
          WantedBy=multi-user.target
    - name: Enable Agent service
      become: true
      service:
        daemon_reload: yes
        name: "{{ agent_service }}"
        enabled: yes
        state: started
    - name: Enable agent_user to run systemctl
      become: true
      copy:
        dest: /etc/sudoers.d/{{ agent_user }}
        content: |
          {{ agent_user }} ALL=NOPASSWD: /usr/bin/systemctl start {{ agent_service }}
          {{ agent_user }} ALL=NOPASSWD: /usr/bin/systemctl stop {{ agent_service }}
          {{ agent_user }} ALL=NOPASSWD: /usr/bin/systemctl restart {{ agent_service }}
        validate: 'visudo -cf %s'

  - name: Install Avantra Agent on Windows
    win_package:
      # NOTE: You can also head to downloads.avantra.com, generate a direct
      # download link, and use it here. Keep in mind that these generated
      # links expire after 12 hours.
      path: http://{{ master_host}}:9050/AgentUpdate/agent-{{ agent_version }}-setup.exe
      creates_path: '{{ agent_win_dir }}'
      arguments:
        - /S
        - /START_SERVICE=1
        - /PORT=9051
        - /D={{ agent_win_dir }}
      state: present
    when: ansible_os_family == 'Windows'

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.