Get the FREE Ultimate OpenClaw Setup Guide →
x

Cloudflare Dns Updater

Use Caution

@xieyuanqing

npx machina-cli add skill @xieyuanqing/cloudflare-dns-updater --openclaw
Files (1)
SKILL.md
3.5 KB

Cloudflare DNS Updater

This skill creates or updates a Cloudflare DNS 'A' record, pointing it to a specified IP address and ensuring it is proxied. It is a foundational tool for automating service deployment and DNS management.

Pre-requisites

This skill requires the CLOUDFLARE_API_TOKEN environment variable to be set with a valid Cloudflare API Token that has DNS edit permissions.

The model should verify this prerequisite before attempting to use the skill. If the variable is not set, it should inform the user and stop.

Core Action: scripts/update-record.py

The core logic is handled by the update-record.py script.

Inputs (Command-Line Arguments)

  • --zone: (Required) The root domain name. Example: example.com
  • --record: (Required) The name of the record (subdomain). Use @ for the root domain itself. Example: www
  • --ip: (Required) The IPv4 address to point the record to.
  • --proxied: (Optional) Boolean (true or false) to set the Cloudflare proxy status. Defaults to true.

Output

The script will print its progress to stdout.

  • On success, it prints a confirmation message and a JSON object of the created/updated record.
  • On failure, it prints a descriptive error message to stderr and exits with a non-zero status code.

Execution Workflow

To use this skill, follow these steps:

  1. Verify Prerequisites: Check if the CLOUDFLARE_API_TOKEN environment variable is set. If not, notify the user and abort.
  2. Gather Inputs: From the user's request, identify the zone, record name, and target ip.
  3. Construct Command: Build the full shell command to execute the script.
  4. Execute Command: Run the command using the exec tool.
  5. Report Result:
    • If the command succeeds, report the successful creation or update to the user.
    • If the command fails, analyze the error message from stderr and report the issue to the user in a clear, understandable way.

Example Usage

User Request: "Point www.example.com to the server's public IP."

AI's Thought Process:

  1. The user wants to update a DNS record on Cloudflare. The cloudflare-dns-updater skill is perfect for this.
  2. I will use the update-record.py script.
  3. I need the zone, record name, and IP.
    • Zone: example.com
    • Record: www
    • IP: I need to find the server's public IP first. I can use curl -s https://ipv4.icanhazip.com/.
  4. I will first get the IP, then construct the final command.
  5. I will execute the command and report the outcome.

AI's Actions:

# Step 1: Get IP
PUBLIC_IP=$(curl -s https://ipv4.icanhazip.com/)

# Step 2: Run the skill's script
python3 skills/cloudflare-dns-updater/scripts/update-record.py \
  --zone "example.com" \
  --record "www" \
  --ip "$PUBLIC_IP"

Failure Strategy

  • If CLOUDFLARE_API_TOKEN is not set: Do not attempt to run the script. Inform the user that the required environment variable is missing and needs to be configured by the administrator.
  • If the script exits with an error: Read the error message from stderr. Common errors include invalid API token, incorrect zone name, or insufficient permissions. Report the specific error to the user.

Source

git clone https://clawhub.ai/xieyuanqing/cloudflare-dns-updaterView on GitHub

Overview

This skill creates or updates a Cloudflare DNS A record to point a subdomain to a specific IP address, ensuring the record is proxied. It enables automated DNS management for deployments and service updates via a simple command-line interface.

How This Skill Works

The updater uses the update-record.py script to call the Cloudflare API with the provided zone, record, IP, and the optional proxied flag (default true). It requires CLOUDFLARE_API_TOKEN with DNS edit permissions and prints progress to stdout; on success, it outputs a JSON object of the updated record.

When to Use It

  • Automate deployment by pointing a subdomain to a new server IP
  • Update DNS for a failover or IP change in production
  • Initialize DNS records for a new service environment
  • Point a root domain or subdomain (record '@' or 'www') to a new IP via automation
  • Integrate DNS updates into CI/CD pipelines to reflect new builds

Quick Start

  1. Step 1: Ensure CLOUDFLARE_API_TOKEN is set with DNS edit permissions
  2. Step 2: Gather inputs: zone, record, and ip values
  3. Step 3: Run the updater: python3 skills/cloudflare-dns-updater/scripts/update-record.py --zone "zone" --record "record" --ip "ip" [--proxied true|false]

Best Practices

  • Securely store CLOUDFLARE_API_TOKEN with the principle of least privilege (DNS edit permissions)
  • Validate zone, record, and IP inputs before executing the script
  • Test changes in a staging environment before affecting production DNS
  • Prefer proxied=true unless you require direct IP exposure
  • Log outcomes and provide clear error messages if the script fails

Example Use Cases

  • Point www.example.com to 203.0.113.42
  • Point api.example.org to 198.51.100.7
  • Point example.com (record @) to 192.0.2.10 with proxied true
  • Update staging.example.com to 10.0.0.5
  • CI script automatically updates multiple DNS records after a deployment

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers