Data Manipulation With Ansible – Ghost Transformations
When you run with Ansible, you are not just pushing configs.
You are bending streams of data: facts, variables, conditions.
Like a Ghost Operator, you read the environment, transform the streams,
and act silently on the system.
This is a field manual for data manipulation in Ansible.
Phase I – Scouting the Battlefield (Reading Data)
First you gather intelligence.
Ansible collects facts by default.
These facts are your reconnaissance: network interfaces, mountpoints, OS data.
- name: Gather facts ansible.builtin.setup:
Once collected, you can see them with:
ansible -m setup target_host
Facts like ansible_mounts
or ansible_env.USER
become your ghostly eyes.
Phase II – Shaping Reality (Transformations)
The Ghost doesn't act on raw data. He bends it.
Use filters, set_fact
, or Jinja2 transformations to reshape the intel:
- name: Extract datastore mountpoint set_fact: datastore_mount: " {{ item.mount }} " loop: " {{ ansible_facts['ansible_mounts'] }} " when: "'/data/disk1' in item.mount"
Now you hold a ghost-variable: datastore_mount
.
Phase III – Silent Execution (Operations)
With transformed data, you strike.
Conditionals make the operation stealthy-only when the target exists.
- name: Create symlink to datastore ansible.builtin.file: src: " {{ datastore_mount }} " dest: "/home/ {{ ansible_env.USER }} /datastore" state: link when: datastore_mount is defined
The link appears. Silent. Functional. Invisible.
Phase IV – Additional Ghost Moves
Other common Ghost Transformations:
- Parsing interfaces to pick the primary IP.
- Building dynamic file paths from environment variables.
- Filtering lists and dicts to choose the right target.
- Combining host vars with inventory vars for hybrid ops.
- name: Pick primary interface set_fact: primary_ip: " {{ ansible_facts['ansible_default_ipv4']['address'] }} "
- name: Build dynamic log path set_fact: log_path: "/var/log/ {{ ansible_env.USER }} /ops.log"
Each move is a transformation. Each transformation is control.
Final Word
The Ghost doesn't fight with brute force.
He bends data until the system aligns with his will.
Fear the silence. Fear the switch.
[ TRANSMISSION ENDS ]