Ansible setup - jhu-information-security-institute/infrastructure GitHub Wiki

Prerequisites:

  • SSH access to host
  • Install sshpass: $ sudo apt-get install sshpass
  • Create ssh keys for your user: $ ssh-keygen -t ed25519 -f id_ed25519 -C <USERNAME>
  • Copy the id_ed25519.pub contents into ~/.ssh
  • Copy the key to the container: $ ssh-copy-id -i ~/.ssh/id_ed25519.pub -p 2222 <USERNAME>@localhost
  • Test the key: $ ssh -i ~/.ssh/id_ed25519 <USERNAME>@localhost -p 2222

Setup:

  1. Create a venv: $ python3 -m venv ansible
  2. Activate your new venv: $ source ansible/bin/activate
  3. Install ansible into the venv: (ansible)$ pip install ansible
  4. Create your inventory and inventory/group_vars folders
  5. Create your inventory files in the inventory folder. E.g., create 01-attack.yml with the following contents
    kali2024:
      hosts: localhost
    
  6. Create your all.yml variables file in the inventory/group_vars folder. Example contents are:
    ansible_connection: ssh
    ansible_port: 2222
    ansible_ssh_private_key_file: ~/.ssh/id_ed25519
    
  7. Verify the inventory: (ansible)$ ansible-inventory -i inventory --list
  8. Ping the hosts in your inventory: (ansible)$ ansible <HOSTNAME> -m ping -i inventory -u <USERNAME>
⚠️ **GitHub.com Fallback** ⚠️