Manage your first Windows target
on this page
This tutorial builds its own project, so you do not need to finish the Quickstart first. You add a Windows host to an inventory, store its password as an encrypted secret, test the connection, and apply a small playbook to the host. The password never appears in plaintext YAML.
Before you start
You need:
- A controller with
preflightinstalled. The controller can run Windows, macOS, or Linux. - A Windows host that the controller can reach over SSH
- A local or domain account that can sign in to that host
- Administrator access on the Windows host
If SSH is not enabled yet, follow Enable remote access on a Windows target with the default SSH setup, then return here.
The tutorial uses password authentication so you can see the secrets workflow. You can switch the host to an SSH key later.
1. Create the project
Create a project directory on the controller:
mkdir preflight-windows-tutorial
cd preflight-windows-tutorial
mkdir playbooksGenerate an age identity for the project:
preflight secret identity generate --out .age/keys.txtThe command prints a public recipient beginning with age1. Copy it. Then add
.age/ to the project’s .gitignore so the private identity stays out of Git:
.age/The recipient is public. The identity in .age/keys.txt is private: give it
only to people and machines that should decrypt this project’s secrets.
2. Configure the host and secret
Create preflight.yml. Replace the recipient, address, and username with your
own values:
project: windows-tutorial
environment: development
secrets:
identity: ".age/keys.txt"
recipients:
- "age1replace-with-your-recipient"
entries:
windows-password:
file: "secrets/windows-password.age"
inventory:
hosts:
- name: kiosk-01
address: 192.168.1.50
transport: ssh
username: exhibit-admin
password: secret:windows-passwordEncrypt the Windows account password:
preflight secret encrypt windows-passwordEnter the password twice when prompted. Preflight writes the encrypted value
to secrets/windows-password.age. The plaintext never reaches preflight.yml
or your shell history.
3. Test the connection
Gather facts from the host:
preflight facts kiosk-01Facts come back only when the address, username, and password work and the host provides Windows PowerShell over SSH.
If the connection fails, stop and work through Troubleshoot remote connections before continuing.
4. Write a Windows playbook
Create playbooks/hello-windows.yml:
name: hello-windows
description: Write a managed file on a Windows target
tasks:
- name: Create the tutorial directory
directory:
path: 'C:\PreflightTutorial'
ensure: present
- name: Write the tutorial file
file:
dest: 'C:\PreflightTutorial\hello.txt'
content: |
Hello from Preflight.
ensure: present5. Inspect and check the run
Validate the YAML and inspect the expanded task list:
preflight validate playbooks/hello-windows.yml
preflight plan playbooks/hello-windows.yml --target kiosk-01Neither command changes the host. Now run the module checks against it:
preflight check playbooks/hello-windows.yml --target kiosk-01check connects to the host and reports the directory and file as pending
changes without creating them.
6. Apply the playbook
preflight apply playbooks/hello-windows.yml --target kiosk-01On the Windows host, open PowerShell and read the file:
Get-Content C:\PreflightTutorial\hello.txtYou should see:
Hello from Preflight.7. Confirm idempotency
Run the check again:
preflight check playbooks/hello-windows.yml --target kiosk-01Preflight reports no changes. The directory and file already match the playbook.
Next steps
- Run a playbook against remote hosts covers groups, selectors, and concurrency.
- Manage secrets covers more recipients, editing, and rekeying.
- The built-in module reference lists modules for services, packages, users, and other Windows state.