Ansible Collection
Use the FeatureSignals Ansible collection to automate feature flag management alongside your infrastructure. Define flags, segments, environments, and API keys in YAML playbooks — idempotent, auditable, and reproducible.
Installation
Install the FeatureSignals collection from Ansible Galaxy:
ansible-galaxy collection install featuresignals.featuresignals
Or declare it in your requirements.yml:
collections:
- name: featuresignals.featuresignals
version: ">=1.0.0"
ansible-galaxy collection install -r requirements.yml
Authentication
All modules require an API token. Provide it via environment variable or the api_token module parameter:
# Option 1: Environment variable (recommended)
# export FEATURESIGNALS_API_TOKEN="fs_api_..."
# Option 2: Module parameter
- name: Create a flag
featuresignals.featuresignals.featuresignals_flag:
api_token: "{{ vault_featuresignals_api_token }}"
project_key: "webapp"
key: "dark-mode"
name: "Dark Mode"
type: "boolean"
default_value: false
Playbook Examples
Provision a Complete Project
A playbook that creates a project, environments, segments, and flags in one run:
---
- name: Provision FeatureSignals resources
hosts: localhost
gather_facts: false
vars:
project_key: "webapp"
tasks:
- name: Create staging environment
featuresignals.featuresignals.featuresignals_environment:
project_key: "{{ project_key }}"
key: "staging"
name: "Staging"
description: "Pre-production staging environment"
- name: Create production environment
featuresignals.featuresignals.featuresignals_environment:
project_key: "{{ project_key }}"
key: "production"
name: "Production"
description: "Production environment"
- name: Create beta users segment
featuresignals.featuresignals.featuresignals_segment:
project_key: "{{ project_key }}"
key: "beta-users"
name: "Beta Users"
description: "Users enrolled in the beta program"
rules:
- attribute: "email"
operator: "ends_with"
values:
- "@beta.featuresignals.com"
- "@testers.featuresignals.com"
- name: Create dark mode feature flag
featuresignals.featuresignals.featuresignals_flag:
project_key: "{{ project_key }}"
key: "dark-mode"
name: "Dark Mode"
description: "Enable the new dark mode UI"
type: "boolean"
default_value: false
- name: Create checkout v2 flag with targeting
featuresignals.featuresignals.featuresignals_flag:
project_key: "{{ project_key }}"
key: "checkout-v2"
name: "Checkout v2"
type: "boolean"
default_value: false
targeting:
rules:
- segment_key: "beta-users"
serve_value: true
rollout:
percentage: 10
serve_value: true
- name: Create production API key
featuresignals.featuresignals.featuresignals_api_key:
project_key: "{{ project_key }}"
name: "Production SDK Key"
type: "server"
environment_keys:
- "production"
register: api_key_result
- name: Store API key in vault
ansible.builtin.set_fact:
prod_sdk_key: "{{ api_key_result.token }}"
no_log: true
Toggle Flags During Deployment
Integrate flag toggling into your deployment playbooks. Enable a maintenance mode flag before deployment, then disable it after:
---
- name: Deploy with feature flag coordination
hosts: app_servers
vars:
project_key: "webapp"
tasks:
- name: Enable maintenance mode flag
featuresignals.featuresignals.featuresignals_flag:
project_key: "{{ project_key }}"
key: "maintenance-mode"
state: "enabled"
delegate_to: localhost
run_once: true
- name: Deploy application
ansible.builtin.import_role:
name: app_deploy
- name: Run smoke tests against new version
ansible.builtin.uri:
url: "https://{{ inventory_hostname }}/health"
return_content: true
register: health_check
- name: Disable maintenance mode flag
featuresignals.featuresignals.featuresignals_flag:
project_key: "{{ project_key }}"
key: "maintenance-mode"
state: "disabled"
delegate_to: localhost
run_once: true
when: health_check.status == 200
Conditional Logic with Flag Info
Use featuresignals_flag_info to query flag state and drive conditional playbook logic:
---
- name: Conditional deployment based on flag state
hosts: localhost
vars:
project_key: "webapp"
tasks:
- name: Get flag state
featuresignals.featuresignals.featuresignals_flag_info:
project_key: "{{ project_key }}"
key: "new-checkout"
register: flag_info
- name: Deploy new checkout service
ansible.builtin.debug:
msg: "Deploying new checkout service..."
when: flag_info.enabled
- name: Skip new checkout service
ansible.builtin.debug:
msg: "New checkout flag is disabled — skipping deployment."
when: not flag_info.enabled
Module Reference
| Module | Description |
|---|---|
| featuresignals_flag | Create, update, toggle, archive, and delete feature flags. |
| featuresignals_segment | Define reusable targeting segments with rules. |
| featuresignals_environment | Manage environments with key, name, and description. |
| featuresignals_api_key | Provision and rotate server-side and client-side API keys. |
| featuresignals_webhook | Configure webhook endpoints for flag change events. |
| featuresignals_flag_info | Retrieve flag details for use in conditional playbook logic. |
Idempotency
All modules are idempotent. Running the same playbook multiple times produces the same result — existing flags are updated if changed, or left untouched if they already match the desired state. The modules return changed: false when no modifications are needed.