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
  tags: componentone

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

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

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

- name: Download ComponentOne license activator
    url: "{{ activationsource }}"
    dest: "{{ path }}\\"
    force: no
  tags: componentone

- name: Check that ComponentOne Activator is downloaded
    path: "{{ path }}\\"
  register: component1activatordownload

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

- name: Install ComponentOne MSI
    path: "{{ path }}\\C1StudioNet_2014v1.msi"
    product_id: "{EF06B3EF-1453-4AE4-9370-26C7290D933D}"
    - 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"
    chdir: "{{ path }}"
  become_user: "{{ domain_name }}\\{{ domain_user }}"
  tags: componentone

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

- name: Rebooting if needed by update
    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}


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

Read more posts by this author.