Infrastructure with Ansible and installing ComponentOne

ComponentOne (C1) is a UI component library and the installation contains a simple installer file and after the installation the installation needs to be registered with a licece key. Each licence can only be used at one machine at a time. I needed to install this library using Ansible on the build agents. Another thing is that there are severeal build agents and there is no need to have this library on each agent, since teh number of projects using it is not that many and it is not a increasing number.

The way I solved the requrement that it not should be installed on each agent, I tagged the agent that should have this installed bit a boolean flag. Then the Ansible role required this flag to be true to execute the task. The next thing then is that I needed a way to distinct the agent with C1 and the ones that do not have C1 installed. That was done by setting an enviroment variable when the installation was complete.

The ComponentOne Ansible role have the directory structure above. In every directory (except the templates) there are a main.yaml file. In the defaults I have variables and that is the place where the licence key is placed. It would be better to have the C1 licence key on a variable that can be set on a per machine basis, but this solved what I needed in the first round. In the vars directory I have defined some other variables that are not sensitive. The definition of the tasks is below and the Powershell script as well.

- name: Gather facts to make sure all variables are up to date
  setup:
  tags: componentone

- name: Create Component One folder
  win_file: path={{ path }} state=directory
  tags: componentone

- name: Download ComponentOne
  win_get_url:
    url: "{{ installersource }}"
    dest: "{{ path }}\\C1StudioNet_2014v1.msi"
    force: no
  tags: componentone

- name: Check that ComponentOne is downloaded
  win_stat:
    path: "{{ path }}\\C1StudioNet_2014v1.msi"
  register: component1download

- name: Download ComponentOne license activator
  win_get_url:
    url: "{{ activationsource }}"
    dest: "{{ path }}\\C1LicenseActivation_2.0.20173.93.zip"
    force: no
  tags: componentone

- name: Check that ComponentOne Activator is downloaded
  win_stat:
    path: "{{ path }}\\C1LicenseActivation_2.0.20173.93.zip"
  register: component1activatordownload

- name: Unzip
  win_unzip:
    dest: "{{ path }}"
    src: "{{ path }}\\C1LicenseActivation_2.0.20173.93.zip"
    rm: True
  when: component1activatordownload.stat.exists
  tags: componentone

- name: Install ComponentOne MSI
  win_package:
    path: "{{ path }}\\C1StudioNet_2014v1.msi"
    product_id: "{EF06B3EF-1453-4AE4-9370-26C7290D933D}"
    arguments:
    - NoLicenseVal=0
    - NoLicenseValRM=0
    state: present
  when: component1download.stat.exists
  register: c1install
  tags: componentone

- name: Copy ComponentOne Activation Script
  win_template: src=ActivateComponentOne.ps1 dest="{{ path }}\\ActivateComponentOne.ps1"
  register: componentoneactivation
  tags: componentone

- name: Activate Component One
  win_shell: ".\\ActivateComponentOne.ps1 -key {{ serial_key }} -compoany {{ company }} -user {{ name }} -pathActivator {{ path }}\\C1LicenseActivation.exe"
  args:
    chdir: "{{ path }}"
  become_user: "{{ domain_name }}\\{{ domain_user }}"
  tags: componentone

- name: Set Enviroment Variable
  win_environment:
    state: present
    name: ComponentOne
    value: Installed
    level: machine
  register: componentoneenv
  tags: componentone

- name: Rebooting if needed by update
  include_role:
    name: BuildAgentReboot
  when: componentoneenv.before_value != "Installed"
  ignore_errors: yes
  tags: componentone

The activation of the C1 library is done with a Powershell script that I have in the Ansible role as a template.

param (
    [string]$key = "{{ serial_key }}",
    [string]$compoany = "{{ company }}",
    [string]$user = "{{ name }}",
    [string]$pathActivator = "{{ path }}\\C1LicenseActivation.exe"
)

&$pathActivator /as:${key} /u:${user} /c:${compoany}

#$LASTEXITCODE

Exit 0

Earlier I always installed the C1 component manually, but automating the process is so much nicer and I got more experience using Ansible.

Teis Lindemark

Passionate software developer and beer brewer

Bergen, Norway https://teilin.net