Snippets
Created by
Heiko Mannherz
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | # 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)
You can clone a snippet to your computer for local editing. Learn more.