Skip to content

Instantly share code, notes, and snippets.

@szabacsik
Created July 7, 2021 06:13
Show Gist options
  • Save szabacsik/ac47535e60da7a1feab1a320ccc05d0a to your computer and use it in GitHub Desktop.
Save szabacsik/ac47535e60da7a1feab1a320ccc05d0a to your computer and use it in GitHub Desktop.
Ansible, WSL2, Vagrant

Ansible, WSL2, Vagrant

Install

apt-get install sshpass
add-apt-repository ppa:ansible/ansible
apt-get update
apt-get install ansible
ansible --version
ansible-galaxy --version

Vagrantfile

Vagrant.configure("2") do |config|
    config.vm.box = "ubuntu/trusty64"
    config.vm.box_check_update = true
    config.vm.provider "virtualbox"
    config.vm.boot_timeout = 600
    config.vm.network "private_network", ip: "192.168.100.101"
    config.vm.network "forwarded_port", guest: 80, host: 80, disabled: true
    config.vm.network "forwarded_port", guest: 1080, host: 1080, disabled: true
    config.vm.network "forwarded_port", guest: 1025, host: 1025, disabled: true
    config.vm.network "forwarded_port", guest: 22, host: 2222, disabled: true
    config.vm.hostname = "ubuntu"
    config.vm.define "ubuntu"
    config.vm.provider :virtualbox do |vb|
        vb.name = "ubuntu"
        vb.memory = 8192
        vb.cpus = 4
    end
    config.vm.synced_folder ".", "/vagrant", disabled: true
    config.vm.provision :shell, path: "./provision.sh"
end

provision.sh

#!/usr/bin/env bash
ln -fs /usr/share/zoneinfo/Europe/Budapest /etc/localtime
dpkg-reconfigure --frontend noninteractive tzdata
locale-gen en_US en_US.UTF-8 hu_HU hu_HU.UTF-8
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
update-locale LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
/etc/init.d/ssh restart
ssh-keygen -f "/home/szabacsik/.ssh/known_hosts" -R "192.168.100.101"
ssh vagrant@192.168.100.101

ansible.cfg

[defaults]
inventory = hosts
host_key_checking = False

hosts

[ubuntu]
192.168.100.101

[all:vars]
ansible_connection=ssh
ansible_user=vagrant
ansible_password=vagrant

ping

ansible -i hosts ubuntu -m ping
ansible -i hosts ubuntu -m ping --ask-pass
ansible -i hosts -m ping all
ansible -i hosts -m ping all --ask-pass
192.168.100.101 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

galaxy

ansible-galaxy install fvarovillodres.lamp

lamp.yaml

- hosts: ubuntu
  roles:
    - role: fvarovillodres.lamp
      become: yes

playbook

ansible-playbook lamp.yaml
ansible-playbook lamp.yaml --ask-pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment