Skip to content

MagicBrownson/pi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Ansible Control for Raspberry Pi

This repository contains Ansible configuration and playbooks to manage a Raspberry Pi on your local network.

Prerequisites

  1. Install Ansible on your local machine:

    # On Windows (using pip)
    pip install ansible
    
    # Or using package manager
    # macOS: brew install ansible
    # Linux: sudo apt install ansible
  2. SSH Access to Raspberry Pi:

    • Ensure SSH is enabled on your Raspberry Pi
    • Set up SSH key authentication (recommended) or use password authentication

Setup

1. Configure Inventory

Edit inventory.ini and update the following:

  • ansible_host: Replace 192.168.1.100 with your Raspberry Pi's IP address or hostname
  • ansible_user: Replace pi with your Raspberry Pi username (default is usually pi)

2. SSH Key Authentication (Recommended)

Generate an SSH key pair if you don't have one:

ssh-keygen -t ed25519 -C "ansible@yourmachine"

Copy your public key to the Raspberry Pi:

ssh-copy-id pi@192.168.1.100

Or manually:

cat ~/.ssh/id_ed25519.pub | ssh pi@192.168.1.100 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

3. Test Connection

Test the connection to your Raspberry Pi:

ansible all -i inventory.ini -m ping

Or use the ping playbook:

ansible-playbook playbooks/ping.yml

Usage

Run Playbooks

# Test connection
ansible-playbook playbooks/ping.yml

# Get system information
ansible-playbook playbooks/system-info.yml

# Update system packages
ansible-playbook playbooks/update-system.yml

Ad-hoc Commands

# Run a command on the Raspberry Pi
ansible raspberry_pi -i inventory.ini -a "uptime"

# Install a package
ansible raspberry_pi -i inventory.ini -m apt -a "name=htop state=present" --become

# Copy a file
ansible raspberry_pi -i inventory.ini -m copy -a "src=local_file.txt dest=/tmp/remote_file.txt"

Troubleshooting

Connection Issues

  1. Check SSH connectivity:

    ssh pi@192.168.1.100
  2. Verify inventory settings:

    • Ensure the IP address/hostname is correct
    • Check that the username is correct
  3. If using password authentication:

    • Uncomment and set ansible_ssh_pass and ansible_become_pass in inventory.ini
    • Or use --ask-pass and --ask-become-pass flags:
      ansible-playbook playbooks/ping.yml --ask-pass --ask-become-pass

Permission Issues

  • Ensure the user has sudo privileges on the Raspberry Pi
  • Use --become flag or set become: yes in playbooks for tasks requiring root access

Creating Custom Playbooks

Create new playbooks in the playbooks/ directory. Example structure:

---
- name: Your playbook name
  hosts: raspberry_pi
  become: yes  # if root access needed
  tasks:
    - name: Task description
      ansible.builtin.command: your_command

Security Notes

  • Keep your inventory file secure, especially if it contains passwords
  • Consider using Ansible Vault for sensitive data:
    ansible-vault encrypt inventory.ini
  • Use SSH key authentication instead of passwords when possible

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors