Skip to content

How to install components with Ansible

Last validated:
View as Markdown

WHAT TO EXPECT

In this article, users will learn how to install different components using Ansible’s playbooks.

PLEASE NOTE

When using the Ansible CLI, provide a -e "persist=yes" to keep the settings (upgrade). Any answer that Ansible recognizes as positive — such as true or 1 — can be used. The default is to NOT persist configuration, so failing to provide the parameter will erase all previous data.

cloudSwXtch installation

cloudSwXtch and OMNI components

By default, the installer installs both the cloudSwXtch and OMNI (which powers wXcked Eye). There should only be one OMNI per installation set, so the first cloudSwXtch installs swxtch,omni and each additional cloudSwXtch should use --components swxtch only. For details on the --components argument, see STEP TWO: Install cloudSwXtch.

Each additional cloudSwXtch must then be captured by the OMNI. For automation, create a capture token on OMNI (swx-cli swxtches capture-token), pass it to every additional cloudSwXtch's install in the SWX_CAPTURE_TOKEN environment variable (as in the playbook below), and capture them from the OMNI host with swx-cli swxtches add --addresses <ip>:9443,<ip>:9443 --capture-token <token>. Without a token, read each one's join code on its host (swx-cli swxtch join-code) and pass it with --join-code. See STEP THREE: Capture the cloudSwXtch with OMNI.

Install or Update a cloudSwXtch

---
- name: cloudSwXtch installation
  hosts: swxtches # Restrict to the actual VMs that will act as cloudSwXtches
  remote_user: ubuntu   # Connect as the standard ubuntu user (replace if your Ubuntu uses a different name). User must be sudoer
  become: no            # CRITICAL: Do NOT become root globally or the installation will fail
  vars:
    ver: "v5.0.0"       # Replace with the actual version you need to install
    components: "swxtch,omni"   # First/primary cloudSwXtch installs both; use "swxtch" on additional cloudSwXtches (only one OMNI per install set)
    token: "si=RDONLY&spr=https&sv=2021-06-08&sr=c&sig=xyPF7SyI1cagUAEIZViqCHz7RroFTy2Fkltn2wwvMzc%3D"
    download_url: "https://sdmcdevstorage.blob.core.windows.net/imagebuilder/swx-swxtch-{{ ver }}.tar.gz?{{ token }}"
    # Use the standard user's home directory
    install_dir: "{{ ansible_env.HOME }}"
  tasks:
    # 1. Download
    - name: Download Swxtch Installer
      ansible.builtin.shell:
        cmd: >-
          curl -fsS -X GET -H "x-ms-date: $(date -u)" "{{ download_url }}" -o "{{ install_dir }}/swx-swxtch-{{ ver }}.tar.gz"
      args:
        creates: "{{ install_dir }}/swx-swxtch-{{ ver }}.tar.gz"
    # 2. Extract Installer
    - name: Extract Installer
      unarchive:
        src: "{{ install_dir }}/swx-swxtch-{{ ver }}.tar.gz"
        dest: "{{ install_dir }}/"
        remote_src: yes
    # 3. Run Install Script
    # Since 'ubuntu' is a sudoer, the script can call 'sudo' internally without password prompts.
    - name: Run Install Script
      shell: >
        ./swx-install.sh --auto_deps --components {{ components }}
        {% if persist | default(false) | bool %} --persist {% endif %}   # This has to be manually configured in Semaphore or sent as an argument in Ansible CLI
      args:
        chdir: "{{ install_dir }}/swx-swxtch-{{ ver }}"
      environment:
        # Optional: an OMNI capture token for the additional cloudSwXtches (kept off the command line)
        SWX_CAPTURE_TOKEN: "{{ capture_token | default('') }}"
      # Explicitly ensuring we do NOT become root here
      become: no
      no_log: "{{ capture_token is defined }}"   # keep the token out of the Ansible output

Clean and Install

Use this to thoroughly clean all previous cloudSwXtch traces:

---
# What to expect:
# This playbook will:
# 1 Clean all containers in the VM (be careful if you have other containers, not swxtch related)
# 2 Install cloudSwXtch
# 3 Clean installation files
- name: Clean cloudSwXtch installation
  hosts: swxtches  # Be sure to define your cloudSwXtch group as swxtches to prevent installation on other VMs
  become: no      # Facts (and install_dir) come from the login user; only the container cleanup runs as root
  vars:
    ver: "v5.0.0"  # Set the target version
    components: "swxtch,omni"   # Use "swxtch" on additional cloudSwXtches (only one OMNI per install set)
    token: "si=RDONLY&spr=https&sv=2021-06-08&sr=c&sig=xyPF7SyI1cagUAEIZViqCHz7RroFTy2Fkltn2wwvMzc%3D"
    download_url: "https://sdmcdevstorage.blob.core.windows.net/imagebuilder/swx-swxtch-{{ ver }}.tar.gz?{{ token }}"
    install_dir: "{{ ansible_env.HOME }}"
  tasks:
    # 1. Stop and remove containers
    - name: Stop and Remove all Docker containers
      shell: |
        if [ "$(docker ps -a -q)" ]; then
            docker stop $(docker ps -a -q)
            docker rm $(docker ps -a -q)
        fi
      args:
        executable: /bin/bash
      become: yes
    # 2. Clean old files
    - name: Remove old swx files
      shell: rm -rf {{ install_dir }}/swx*
      become: no
    # 3. Download
    - name: Download Swxtch Installer
      shell: >-
        curl -fsS -X GET -H "x-ms-date: $(date -u)" "{{ download_url }}" -o "{{ install_dir }}/swx-swxtch-{{ ver }}.tar.gz"
      args:
        executable: /bin/bash
      become: no
    # 4. Extract
    - name: Extract Installer
      unarchive:
        src: "{{ install_dir }}/swx-swxtch-{{ ver }}.tar.gz"
        dest: "{{ install_dir }}/"
        remote_src: yes
      become: no
    # 5. Run Install Script
    - name: Run Install Script
      shell: "./swx-install.sh --auto_deps --components {{ components }}"
      args:
        chdir: "{{ install_dir }}/swx-swxtch-{{ ver }}"
      become: no # cloudSwXtch installation must be done with a normal (non-root) user
    # 6. Final Cleanup
    - name: Final Cleanup
      shell: rm -rf {{ install_dir }}/swx-swxtch-{{ ver }}*
      become: no

swXtchBridge installation

Client installs are pinned to the cloudSwXtch's key: pass its key pin as swx_pin (swx-cli swxtch pin on the cloudSwXtch host prints it, and the cloudSwXtch installer shows it at the end of the install). Optionally, pass an enrol token as enroll_token so the clients are approved without an administrator; the playbooks hand it to the installer in SWX_ENROLL_TOKEN, never on the command line. Without a token, approve the clients in Authorizations or with swx-cli clients authorize.

The swXtchBridge needs to know the control, data, and user interface for the installation. There is also an option to upgrade (keeping the old configuration), and to choose the DPDK driver mode (--dpdk_driver). Check the Installing swXtchBridge page for details.

---
- name: Install swXtchBridge
  hosts: label_function_bridge
  become: no
  vars:
    # Required: swx_ctrl_ip, swx_pin (sha256//...), nic_d (data interface; the installer needs it when it runs non-interactively)
    # Optional: nic_c, nic_i (Strings), enroll_token (String)
    # Optional: dpdk_driver (String)
    # Optional: persist (Boolean)
  pre_tasks:
    - name: Verify cloudSwXtch Control IP is defined
      fail:
        msg: "❌ ERROR: You must provide the cloudSwXtch Control IP! Use '-e swx_ctrl_ip=...'."
      when: swx_ctrl_ip is not defined or swx_pin is not defined
  tasks:
    - name: Download and Run swXtchBridge Installer
      shell: >
        set -o pipefail &&
        curl -fsS -k --pinnedpubkey '{{ swx_pin }}' https://{{ swx_ctrl_ip }}:9443/swx/services/install/swx-bridge-install.sh
        | bash -s -- --auto_deps
        {% if nic_c is defined and nic_c | length > 0 %} -c {{ nic_c }} {% endif %}
        {% if nic_d is defined and nic_d | length > 0 %} -d {{ nic_d }} {% endif %}
        {% if nic_i is defined and nic_i | length > 0 %} -i {{ nic_i }} {% endif %}
        {% if dpdk_driver is defined and dpdk_driver | length > 0 %} --dpdk_driver {{ dpdk_driver }} {% endif %}
        {% if persist | default(false) | bool %} --persist {% endif %}
      args:
        executable: /bin/bash
      environment:
        SWX_ENROLL_TOKEN: "{{ enroll_token | default('') }}"
      register: install_result
    - name: Display Installation Output
      debug:
        msg: "{{ install_result.stdout_lines }}"

When using the Ansible CLI, the parameters for the installation are:

ansible-playbook -i inventory playbooks/install-bridge.yaml \
  -e "swx_ctrl_ip=10.128.0.50" \ # can be a hostname if DNS is configured. Parameter needed
  -e "swx_pin=sha256//<pin>" \   # the cloudSwXtch's key pin. Parameter needed
  -e "nic_c=ens4" \              # control interface name. Parameter needed
  -e "nic_d=ens5" \              # data    interface name. Parameter needed
  -e "nic_i=ens6" \              # user    interface name. Parameter needed
  -e "dpdk_driver=af_packet" \   # DPDK driver mode. Optional
  -e "persist=yes"               # if this is an upgrade (will preserve settings). Optional. Default NO

xNIC installation (Linux)

---
- name: Install xNIC Agent
  hosts: label_function_agent  # Adjust this to match your target group or use 'all'
  become: no  # CRITICAL: Script forbids running as root
  vars:
    # swx_ctrl_ip: (Required)
    # swx_pin: (Required) the cloudSwXtch's key pin, sha256//...
    # xnic_type: (Optional; when not set, the installer selects Type 2 on kernel 5.11 or newer, otherwise Type 1)
    # persist: (Optional boolean). Used to upgrade and preserve settings (and the xNIC's identity and approval).
    # enroll_token: (Optional) enrol token from OMNI: the xNIC is approved without an administrator
  pre_tasks:
    - name: Verify cloudSwXtch Control IP is defined
      fail:
        msg: "❌ ERROR: You must provide the cloudSwXtch Control IP (swx_ctrl_ip) and key pin (swx_pin)!"
      when: swx_ctrl_ip is not defined or swx_pin is not defined
  tasks:
    - name: Run xNIC Installer
      shell: >
        set -o pipefail &&
        curl -fsS -k --pinnedpubkey '{{ swx_pin }}' https://{{ swx_ctrl_ip }}:9443/swx/services/install/swx-xnic-install.sh
        | bash -s --
        {% if xnic_type is defined %} -t {{ xnic_type }} {% endif %}
        {% if persist | default(false) | bool %} --persist {% endif %}
      args:
        executable: /bin/bash
      environment:
        SWX_ENROLL_TOKEN: "{{ enroll_token | default('') }}"
      register: install_result
    - name: Display Installation Output
      debug:
        msg: "{{ install_result.stdout_lines }}"

xNIC installation (Windows)

UNTESTED

The Windows xNIC playbook below is provided as a starting point and has not yet been tested. It requires the ansible.windows collection and Ansible connectivity to Windows (WinRM or SSH). win_shell runs Windows PowerShell, which the installer needs to enforce the cloudSwXtch's key pin (PowerShell 7 cannot). Validate it before using in production.

---
- name: Install xNIC Agent (Windows)
  hosts: label_function_agent_windows   # Adjust this to match your Windows target group
  gather_facts: no
  # Requirements: the ansible.windows collection, and Ansible connectivity to Windows (WinRM or SSH).
  vars:
    # xnic_windows_command: (Required) the cloudSwXtch's "xNIC (Windows)" install command, as
    #   'swx-cli swxtch pin' on the cloudSwXtch host prints it (it is pinned to the cloudSwXtch's key)
    # xnic_type: (Optional, default is 2)
    # enroll_token: (Optional) enrol token from OMNI: the xNIC is approved without an administrator
  pre_tasks:
    - name: Verify the install command is defined
      ansible.builtin.fail:
        msg: "❌ ERROR: You must provide the cloudSwXtch's Windows install command (xnic_windows_command)!"
      when: xnic_windows_command is not defined
  tasks:
    - name: Download (pinned) and run the xNIC installer (Windows PowerShell)
      # A first install reboots Windows at the end; append -no_mc_exempt to skip it, or add an ansible.windows.win_reboot task after this one.
      ansible.windows.win_shell: "{{ xnic_windows_command }} -t {{ xnic_type | default('2') }}"
      environment:
        SWX_ENROLL_TOKEN: "{{ enroll_token | default('') }}"
      register: install_result
    - name: Display Installation Output
      ansible.builtin.debug:
        msg: "{{ install_result.stdout_lines }}"