Skip to content
ansible-tmmPublic

About

automation for x, formerly known as Twitter

Resources

Code of conduct

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

20 Commits

Folders and files

Repository files navigation

x_ansible

Post messages to social platforms from Ansible playbooks.

Supported platforms

Platform Cost Auth method Token refresh Docs
Bluesky Free App Password Never bluesky/README.md
LinkedIn Free OAuth 2.0 Every 60 days linkedin/README.md
X (Twitter) Paid / Free* OAuth 1.0a / Cookies Never / Weeks x/README.md
Reddit Free OAuth 2.0 (script) Per-request reddit/README.md
Threads Free OAuth 2.0 Every 60 days threads/README.md
AI Content Generation Free Bearer token (MAAS) Never ai/README.md

*X official API requires a paid plan (~$200+/month). Browser automation is free but against TOS.

Quick start

# Clone and setup
git clone <repo-url> && cd x_ansible
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Post to Bluesky (easiest)

export BLUESKY_HANDLE="yourname.bsky.social"
export BLUESKY_APP_PASSWORD="xxxx-xxxx-xxxx-xxxx"
ansible-playbook bluesky/post_to_bluesky.yml -e 'post_text=hello from ansible'

Post to LinkedIn

# First time only — opens browser for OAuth
export LINKEDIN_CLIENT_ID="your-client-id"
export LINKEDIN_CLIENT_SECRET="your-client-secret"
python linkedin/files/setup_linkedin_token.py

# Then post (no env vars needed — reads saved token)
ansible-playbook linkedin/post_to_linkedin.yml -e 'post_text=hello from ansible'

Post to X (browser automation)

# First time only
playwright install chromium
python x/files/setup_x_session.py

# Then post
ansible-playbook x/post_to_x_browser.yml -e 'post_text=hello from ansible'

Post to Reddit

export REDDIT_CLIENT_ID="your-client-id"
export REDDIT_CLIENT_SECRET="your-client-secret"
export REDDIT_USERNAME="your-username"
export REDDIT_PASSWORD="your-password"
ansible-playbook reddit/post_to_reddit.yml \
  -e 'title="My Post Title" url="https://example.com" subreddit="ansible"'

Post to Threads

# First time only
export THREADS_APP_ID="your-threads-app-id"
export THREADS_APP_SECRET="your-threads-app-secret"
python threads/files/setup_threads_token.py

# Then post
ansible-playbook threads/post_to_threads.yml -e 'post_text=hello from ansible'

Project structure

x_ansible/
├── ai/
│   ├── tasks/ask_ai.yml           # Reusable AI task (any OpenAI-compatible API)
│   ├── generate_post.yml          # Generate + preview + publish workflow
│   └── README.md
├── bluesky/
│   ├── library/bluesky_post.py
│   ├── vars/credentials_example.yml
│   ├── post_to_bluesky.yml
│   └── README.md
├── linkedin/
│   ├── library/linkedin_post.py
│   ├── files/setup_linkedin_token.py
│   ├── vars/credentials_example.yml
│   ├── post_to_linkedin.yml
│   └── README.md
├── x/
│   ├── library/x_post.py, x_post_browser.py
│   ├── files/setup_x_session.py
│   ├── vars/credentials_example.yml
│   ├── post_to_x.yml, post_to_x_browser.yml
│   └── README.md
├── reddit/
│   ├── library/reddit_post.py
│   ├── post_to_reddit.yml
│   └── README.md
├── threads/
│   ├── library/threads_post.py
│   ├── files/setup_threads_token.py
│   ├── post_to_threads.yml
│   └── README.md
├── webapp/
│   ├── app.py
│   ├── generate_only.yml
│   ├── templates/index.html
│   └── static/style.css
├── venv/                          (gitignored)
├── requirements.txt
├── ansible.cfg
└── .gitignore

Requirements

  • Python 3.9+
  • macOS or Linux
  • A virtual environment (included in setup)

All Python dependencies (Ansible, requests, requests-oauthlib, playwright) are installed into the venv via requirements.txt.

Usage pattern

Every playbook follows the same pattern:

source venv/bin/activate
ansible-playbook <platform>/post_to_<platform>.yml -e 'post_text=Your message here'

All playbooks support:

  • -e 'post_text=...' — pass text as an extra variable
  • --check — dry run (validates inputs without posting)
  • --ask-vault-pass — decrypt Vault-encrypted credentials

Credential management

Each platform supports credentials via (in priority order):

  1. Module parameters — for Ansible Vault usage
  2. Environment variables — for shell/CI usage
  3. Config files — saved by setup scripts (LinkedIn, X browser)

Secrets are never stored in playbooks or committed to git.

Idempotency

Posting is inherently non-idempotent. Every successful run creates a new post. Running the same playbook twice produces two posts. Design your automation accordingly (e.g., use external state or locks to prevent duplicates).

Common tasks

Generate AI posts for all platforms (preview)

export MAAS="your-maas-key"
ansible-playbook ai/generate_post.yml -e 'content="Just shipped a new feature"'

Generate + publish to all platforms

ansible-playbook ai/generate_post.yml -e 'content="Just shipped a new feature" publish=true'

Post to multiple platforms manually

ansible-playbook bluesky/post_to_bluesky.yml linkedin/post_to_linkedin.yml \
  -e 'post_text=hello from ansible'

Set up a cron job (post daily)

crontab -e
# Add:
0 9 * * * cd /path/to/x_ansible && source venv/bin/activate && ansible-playbook bluesky/post_to_bluesky.yml -e 'post_text=Good morning'

License

See LICENSE.

About

automation for x, formerly known as Twitter

Resources

Code of conduct

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages