Skip to content

Instantly share code, notes, and snippets.

@rduplain
Last active November 28, 2019 00:17
Show Gist options
  • Save rduplain/65128f8eff98723c88a52688a7a204c3 to your computer and use it in GitHub Desktop.
Save rduplain/65128f8eff98723c88a52688a7a204c3 to your computer and use it in GitHub Desktop.

Revisions

  1. rduplain revised this gist Nov 28, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,8 @@ up.
    Run each Vagrantfile (see _Usage_ below) then **connect to throwaway virtual
    machines on your network**.

    These Vagrantfiles assist in experimenting with configuration and setting up
    specific scenarios. To test infrastructure, see [Kitchen](https://kitchen.ci/).
    These Vagrantfiles assist in experimenting with configuration and specific
    scenarios. **To test infrastructure, see [Kitchen](https://kitchen.ci/).**


    ### Features
  2. rduplain revised this gist Nov 28, 2019. 2 changed files with 16 additions and 15 deletions.
    20 changes: 10 additions & 10 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -9,9 +9,9 @@ guests appear as hosts on the LAN, providing a local ephemeral cloud.**

    The virtual machines here are similar, but different. One provides **Ubuntu
    14.04 LTS ("trusty")**, another provides **Ubuntu 18.04 LTS ("bionic")**, and
    another provides **Red Hat Enterprise Linux 8 ("rhel8")**. Together they
    provide a test environment for the basis of an inventory to test configuration
    on machines old and new.
    another provides **CentOS Linux 8 ("centos8")**. Together they provide a test
    environment for the basis of an inventory to test configuration on machines old
    and new.

    More broadly, these Vagrantfiles demonstrate **how to get multiple virtual
    machines on your LAN for testing from your development machine** with
    @@ -70,10 +70,10 @@ Install [VirtualBox][VirtualBox] and [vagrant][vagrant].
    Put each Vagrantfile into its own directory:

    ```sh
    mkdir -p bionic trusty rhel8
    mkdir -p bionic trusty centos8
    mv Vagrantfile.bionic ./bionic/Vagrantfile
    mv Vagrantfile.trusty ./trusty/Vagrantfile
    mv Vagrantfile.rhel8 ./rhel8/Vagrantfile
    mv Vagrantfile.centos8 ./centos8/Vagrantfile
    ```

    Update each Vagrantfile with the identifier of your network interface. See the
    @@ -102,7 +102,7 @@ vagrant up && vagrant reload
    ```

    ```sh
    cd ./rhel8
    cd ./centos8
    vagrant up && vagrant reload
    ```

    @@ -127,15 +127,15 @@ Connect to each host:
    ```sh
    ssh vagrant@<resulting_bionic_ip>
    ssh vagrant@<resulting_trusty_ip>
    ssh vagrant@<resulting_rhel8_ip>
    ssh vagrant@<resulting_centos8_ip>
    ```

    If your network resolves hostnames on the LAN:

    ```sh
    ssh vagrant@bionic
    ssh vagrant@trusty
    ssh vagrant@rhel8
    ssh vagrant@centos8
    ```

    Helpful configuration for `~/.ssh/config`:
    @@ -149,7 +149,7 @@ Host trusty
    User vagrant
    StrictHostKeyChecking no
    Host rhel8
    Host centos8
    User vagrant
    StrictHostKeyChecking no
    ```
    @@ -160,7 +160,7 @@ change host sshd keys on each newly created `vagrant up` virtual machine.
    ```sh
    ssh bionic
    ssh trusty
    ssh rhel8
    ssh centos8
    ```

    Now you have hosts on the LAN, accessible by SSH, for testing configuration
    11 changes: 6 additions & 5 deletions Vagrantfile.rhel8 → Vagrantfile.centos8
    Original file line number Diff line number Diff line change
    @@ -11,10 +11,11 @@
    # vagrant ssh

    Vagrant.configure(2) do |config|
    config.vm.define "rhel8"
    config.vm.hostname = "rhel8"
    config.vm.define "centos8"
    config.vm.hostname = "centos8"

    config.vm.box = "generic/rhel8"
    config.vm.box = "centos/8"
    config.vm.box_version = "1905.1"
    config.vm.box_check_update = false

    # Below, bridge value is specific to the host machine interfaces.
    @@ -26,13 +27,13 @@ Vagrant.configure(2) do |config|
    # * Ctrl-C, update Vagrantfile.
    config.vm.network "public_network",
    bridge: "...",
    mac: "02CC50F0e108",
    mac: "02CC50Fce108",
    use_dhcp_assigned_default_route: true

    config.vm.provider "virtualbox" do |vb|
    vb.cpus = 2
    vb.memory = "512"
    vb.name = "rhel8"
    vb.name = "centos8"

    vb.customize ["modifyvm", :id, "--audio", "none"]
    vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
  3. rduplain revised this gist Nov 27, 2019. 4 changed files with 97 additions and 13 deletions.
    36 changes: 25 additions & 11 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -3,18 +3,19 @@
    ### Overview

    Configuration management that runs over SSH, namely Ansible, benefits in having
    test machines available on the network. The enclosed Vagrantfiles provide two
    virtual machines to run as guests on the developer's machine. **The guests
    appear as hosts on the LAN, providing a local ephemeral cloud.**
    test machines available on the network. The enclosed Vagrantfiles provide
    multiple virtual machines to run as guests on the developer's machine. **The
    guests appear as hosts on the LAN, providing a local ephemeral cloud.**

    The virtual machines here are similar, but different. One provides **Ubuntu
    14.04 LTS ("trusty")** and the other provides **Ubuntu 18.04 LTS ("bionic")**.
    Together they provide a test environment for the basis of an inventory to test
    configuration on machines old and new.
    14.04 LTS ("trusty")**, another provides **Ubuntu 18.04 LTS ("bionic")**, and
    another provides **Red Hat Enterprise Linux 8 ("rhel8")**. Together they
    provide a test environment for the basis of an inventory to test configuration
    on machines old and new.

    More broadly, these two Vagrantfiles demonstrate **how to get multiple virtual
    More broadly, these Vagrantfiles demonstrate **how to get multiple virtual
    machines on your LAN for testing from your development machine** with
    [vagrant][vagrant]. A simple `diff` of the two Vagrantfiles suggests how you
    [vagrant][vagrant]. A simple `diff` of any two Vagrantfiles suggests how you
    might template the configuration for larger projects, given enough RAM.

    The **shell provision in the Vagrantfile provides the starting point** as the
    @@ -58,7 +59,7 @@ to create the virtual machine.
    configuring the network bridge, they include details about the local developer
    machine (including use of VirtualBox, which is a developer preference).
    Therefore, these Vagrantfiles cannot be shared across developer machines and
    therefore should not be checked into version control without additional
    therefore should not be checked into version control _as-is_ without additional
    consideration.


    @@ -69,9 +70,10 @@ Install [VirtualBox][VirtualBox] and [vagrant][vagrant].
    Put each Vagrantfile into its own directory:

    ```sh
    mkdir -p trusty bionic
    mkdir -p bionic trusty rhel8
    mv Vagrantfile.bionic ./bionic/Vagrantfile
    mv Vagrantfile.trusty ./trusty/Vagrantfile
    mv Vagrantfile.rhel8 ./rhel8/Vagrantfile
    ```

    Update each Vagrantfile with the identifier of your network interface. See the
    @@ -99,8 +101,13 @@ cd ./trusty
    vagrant up && vagrant reload
    ```

    ```sh
    cd ./rhel8
    vagrant up && vagrant reload
    ```

    You can run these in parallel, but if you changed the Vagrantfile to use the
    same `config.vm.box` to make both run the same Ubuntu version, then let vagrant
    same `config.vm.box` to make two run the same Ubuntu version, then let vagrant
    complete one host before starting the other. If there are any errors, review
    the log output carefully, as the issue is likely with your particular vagrant
    configuration or the underlying VirtualBox installation.
    @@ -120,13 +127,15 @@ Connect to each host:
    ```sh
    ssh vagrant@<resulting_bionic_ip>
    ssh vagrant@<resulting_trusty_ip>
    ssh vagrant@<resulting_rhel8_ip>
    ```

    If your network resolves hostnames on the LAN:

    ```sh
    ssh vagrant@bionic
    ssh vagrant@trusty
    ssh vagrant@rhel8
    ```

    Helpful configuration for `~/.ssh/config`:
    @@ -139,6 +148,10 @@ Host bionic
    Host trusty
    User vagrant
    StrictHostKeyChecking no
    Host rhel8
    User vagrant
    StrictHostKeyChecking no
    ```

    This allows a more direct ssh invocation and appreciates that vagrant will
    @@ -147,6 +160,7 @@ change host sshd keys on each newly created `vagrant up` virtual machine.
    ```sh
    ssh bionic
    ssh trusty
    ssh rhel8
    ```

    Now you have hosts on the LAN, accessible by SSH, for testing configuration
    2 changes: 1 addition & 1 deletion Vagrantfile.bionic
    Original file line number Diff line number Diff line change
    @@ -68,7 +68,7 @@ Vagrant.configure(2) do |config|
    apt-get update
    apt-get dist-upgrade -y
    apt-get install -y curl screen vim tree zip unzip git-core tig build-essential
    apt-get install -y vim
    update-alternatives --set editor /usr/bin/vim.basic
    echo Adding additional user authorized keys ...
    70 changes: 70 additions & 0 deletions Vagrantfile.rhel8
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    # -*- mode: ruby -*-
    # vi: set ft=ruby :

    # Setup, first time only:
    #
    # vagrant up && vagrant reload
    #
    # Usage:
    #
    # vagrant up
    # vagrant ssh

    Vagrant.configure(2) do |config|
    config.vm.define "rhel8"
    config.vm.hostname = "rhel8"

    config.vm.box = "generic/rhel8"
    config.vm.box_check_update = false

    # Below, bridge value is specific to the host machine interfaces.
    # To display valid options:
    #
    # * Remove bridge key below.
    # * vagrant up
    # * Review options presented interactively by Vagrant.
    # * Ctrl-C, update Vagrantfile.
    config.vm.network "public_network",
    bridge: "...",
    mac: "02CC50F0e108",
    use_dhcp_assigned_default_route: true

    config.vm.provider "virtualbox" do |vb|
    vb.cpus = 2
    vb.memory = "512"
    vb.name = "rhel8"

    vb.customize ["modifyvm", :id, "--audio", "none"]
    vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
    vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
    end

    config.vm.synced_folder ".", "/vagrant", disabled: true

    # Prepare to have all local authorized keys also be authorized by vagrant.
    # Append to ~/.ssh/authorized_keys in shell provision below.
    config.vm.provision "file",
    source: "~/.ssh/authorized_keys",
    destination: "~/.ssh/user_authorized_keys"

    config.vm.provision "shell",
    privileged: true, keep_color: true, inline: <<-SHELL
    export LANGUAGE=en_US.UTF-8
    export LANG=$LANGUAGE
    export LC_ALL=$LANGUAGE
    localectl set-locale LANG=$LANG
    timedatectl set-timezone America/New_York
    timedatectl status
    yum update -y
    yum install -y vim
    echo Adding additional user authorized keys ...
    sort -u /home/vagrant/.ssh/{user_authorized_keys,authorized_keys} > \
    /tmp/authorized_keys
    mv /tmp/authorized_keys /home/vagrant/.ssh/authorized_keys
    SHELL
    end
    2 changes: 1 addition & 1 deletion Vagrantfile.trusty
    Original file line number Diff line number Diff line change
    @@ -68,7 +68,7 @@ Vagrant.configure(2) do |config|
    apt-get update
    apt-get dist-upgrade -y
    apt-get install -y curl screen vim tree zip unzip git-core tig build-essential
    apt-get install -y vim
    update-alternatives --set editor /usr/bin/vim.basic
    echo Adding additional user authorized keys ...
  4. rduplain revised this gist Nov 9, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,9 @@ up.
    Run each Vagrantfile (see _Usage_ below) then **connect to throwaway virtual
    machines on your network**.

    These Vagrantfiles assist in experimenting with configuration and setting up
    specific scenarios. To test infrastructure, see [Kitchen](https://kitchen.ci/).


    ### Features

  5. rduplain revised this gist Nov 9, 2019. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,16 @@ A Vagrantfile assumes that the machine running vagrant has enough CPUs and RAM
    to create the virtual machine.


    ### Quickstart

    * Add the ID of your machine's network interface to each Vagrantfile.
    (See the comment "To display valid options..." in the Vagrantfile.)
    * Set one Vagrantfile per directory; run `vagrant` in each directory.
    * Bring hosts up with `vagrant up && vagrant reload`.
    * Stop hosts with `vagrant halt`.
    * Delete hosts with `vagrant destroy`.


    ### Preface to Usage

    **Vagrantfiles for testing only. Run only on trusted networks.**
    @@ -92,6 +102,9 @@ complete one host before starting the other. If there are any errors, review
    the log output carefully, as the issue is likely with your particular vagrant
    configuration or the underlying VirtualBox installation.

    When you are ready to stop hosts, run `vagrant halt` in the directory of each
    Vagrantfile. Run `vagrant destroy` to delete the virtual machine.

    Making changes to the shell provision in the Vagrantfile? With the host
    running, run:

  6. rduplain revised this gist Nov 9, 2019. 1 changed file with 144 additions and 1 deletion.
    145 changes: 144 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,144 @@
    _@rduplain is typing_
    ## Vagrantfiles for testing configuration management (Ansible).

    ### Overview

    Configuration management that runs over SSH, namely Ansible, benefits in having
    test machines available on the network. The enclosed Vagrantfiles provide two
    virtual machines to run as guests on the developer's machine. **The guests
    appear as hosts on the LAN, providing a local ephemeral cloud.**

    The virtual machines here are similar, but different. One provides **Ubuntu
    14.04 LTS ("trusty")** and the other provides **Ubuntu 18.04 LTS ("bionic")**.
    Together they provide a test environment for the basis of an inventory to test
    configuration on machines old and new.

    More broadly, these two Vagrantfiles demonstrate **how to get multiple virtual
    machines on your LAN for testing from your development machine** with
    [vagrant][vagrant]. A simple `diff` of the two Vagrantfiles suggests how you
    might template the configuration for larger projects, given enough RAM.

    The **shell provision in the Vagrantfile provides the starting point** as the
    preexisting state of the virtual machine before configuration management picks
    up.

    Run each Vagrantfile (see _Usage_ below) then **connect to throwaway virtual
    machines on your network**.


    ### Features

    * Configure each host with 2 CPUs and 1GB RAM.
    * Disable vagrant's default bind/synced folder at `/vagrant`.
    * Provision with inline shell to set the initial state.
    * Connect to the public network.
    * Append all developer authorized_keys to vagrant SSH.

    A Vagrantfile assumes that the machine running vagrant has enough CPUs and RAM
    to create the virtual machine.


    ### Preface to Usage

    **Vagrantfiles for testing only. Run only on trusted networks.**

    **Before you `git add .` ...** These Vagrantfiles are _mostly_ portable, but in
    configuring the network bridge, they include details about the local developer
    machine (including use of VirtualBox, which is a developer preference).
    Therefore, these Vagrantfiles cannot be shared across developer machines and
    therefore should not be checked into version control without additional
    consideration.


    ### Usage

    Install [VirtualBox][VirtualBox] and [vagrant][vagrant].

    Put each Vagrantfile into its own directory:

    ```sh
    mkdir -p trusty bionic
    mv Vagrantfile.bionic ./bionic/Vagrantfile
    mv Vagrantfile.trusty ./trusty/Vagrantfile
    ```

    Update each Vagrantfile with the identifier of your network interface. See the
    comment "To display valid options..." in the Vagrantfile.

    Is your LAN configured for DHCP... will the router accept any new host? If so,
    keep the `dhcp` configuration already in place. If not, review the [public
    networks][public networks] documentation and consider setting `ip:
    "192.168.1.99"` using whatever static IP value is appropriate.

    Maintain a unique, fake MAC address for each Vagrantfile. This is already done
    in the Vagrantfiles provided, but note that you should adjust the last 6
    characters of each mac to a unique value when forking Vagrantfile
    configurations.

    Bring up each host:

    ```sh
    cd ./bionic
    vagrant up && vagrant reload
    ```

    ```sh
    cd ./trusty
    vagrant up && vagrant reload
    ```

    You can run these in parallel, but if you changed the Vagrantfile to use the
    same `config.vm.box` to make both run the same Ubuntu version, then let vagrant
    complete one host before starting the other. If there are any errors, review
    the log output carefully, as the issue is likely with your particular vagrant
    configuration or the underlying VirtualBox installation.

    Making changes to the shell provision in the Vagrantfile? With the host
    running, run:

    ```sh
    vagrant provision
    ```

    Connect to each host:

    ```sh
    ssh vagrant@<resulting_bionic_ip>
    ssh vagrant@<resulting_trusty_ip>
    ```

    If your network resolves hostnames on the LAN:

    ```sh
    ssh vagrant@bionic
    ssh vagrant@trusty
    ```

    Helpful configuration for `~/.ssh/config`:

    ```conf
    Host bionic
    User vagrant
    StrictHostKeyChecking no
    Host trusty
    User vagrant
    StrictHostKeyChecking no
    ```

    This allows a more direct ssh invocation and appreciates that vagrant will
    change host sshd keys on each newly created `vagrant up` virtual machine.

    ```sh
    ssh bionic
    ssh trusty
    ```

    Now you have hosts on the LAN, accessible by SSH, for testing configuration
    management.

    --@rduplain


    [VirtualBox]: https://www.virtualbox.org/
    [vagrant]: https://www.vagrantup.com/
    [public networks]: https://www.vagrantup.com/docs/networking/public_network.html
  7. rduplain revised this gist Nov 8, 2019. 2 changed files with 158 additions and 0 deletions.
    79 changes: 79 additions & 0 deletions Vagrantfile.bionic
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    # -*- mode: ruby -*-
    # vi: set ft=ruby :

    # Setup, first time only:
    #
    # vagrant up && vagrant reload
    #
    # Usage:
    #
    # vagrant up
    # vagrant ssh

    Vagrant.configure(2) do |config|
    config.vm.define "bionic"
    config.vm.hostname = "bionic"

    config.vm.box = "ubuntu/bionic64"
    config.vm.box_check_update = false

    # Below, bridge value is specific to the host machine interfaces.
    # To display valid options:
    #
    # * Remove bridge key below.
    # * vagrant up
    # * Review options presented interactively by Vagrant.
    # * Ctrl-C, update Vagrantfile.
    config.vm.network "public_network",
    bridge: "...",
    mac: "02CC50F01804",
    use_dhcp_assigned_default_route: true

    config.vm.provider "virtualbox" do |vb|
    vb.cpus = 2
    vb.memory = "1024"
    vb.name = "bionic"

    vb.customize ["modifyvm", :id, "--audio", "none"]
    vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
    vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
    end

    config.vm.synced_folder ".", "/vagrant", disabled: true

    # Prepare to have all local authorized keys also be authorized by vagrant.
    # Append to ~/.ssh/authorized_keys in shell provision below.
    config.vm.provision "file",
    source: "~/.ssh/authorized_keys",
    destination: "~/.ssh/user_authorized_keys"

    config.vm.provision "shell",
    privileged: true, keep_color: true, inline: <<-SHELL
    export LANGUAGE=en_US.UTF-8
    export LANG=$LANGUAGE
    export LC_ALL=$LANGUAGE
    export DEBIAN_FRONTEND=noninteractive
    locale-gen $LANGUAGE
    update-locale LANGUAGE=$LANGUAGE
    update-locale LANG=$LANG
    update-locale LC_ALL=$LC_ALL
    dpkg-reconfigure locales
    timedatectl set-timezone America/New_York
    dpkg-reconfigure tzdata
    apt-get update
    apt-get dist-upgrade -y
    apt-get install -y curl screen vim tree zip unzip git-core tig build-essential
    update-alternatives --set editor /usr/bin/vim.basic
    echo Adding additional user authorized keys ...
    sort -u /home/vagrant/.ssh/{user_authorized_keys,authorized_keys} > \
    /tmp/authorized_keys
    mv /tmp/authorized_keys /home/vagrant/.ssh/authorized_keys
    SHELL
    end
    79 changes: 79 additions & 0 deletions Vagrantfile.trusty
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    # -*- mode: ruby -*-
    # vi: set ft=ruby :

    # Setup, first time only:
    #
    # vagrant up && vagrant reload
    #
    # Usage:
    #
    # vagrant up
    # vagrant ssh

    Vagrant.configure(2) do |config|
    config.vm.define "trusty"
    config.vm.hostname = "trusty"

    config.vm.box = "ubuntu/trusty64"
    config.vm.box_check_update = false

    # Below, bridge value is specific to the host machine interfaces.
    # To display valid options:
    #
    # * Remove bridge key below.
    # * vagrant up
    # * Review options presented interactively by Vagrant.
    # * Ctrl-C, update Vagrantfile.
    config.vm.network "public_network",
    bridge: "...",
    mac: "02CC50F01404",
    use_dhcp_assigned_default_route: true

    config.vm.provider "virtualbox" do |vb|
    vb.cpus = 2
    vb.memory = "1024"
    vb.name = "trusty"

    vb.customize ["modifyvm", :id, "--audio", "none"]
    vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
    vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
    end

    config.vm.synced_folder ".", "/vagrant", disabled: true

    # Prepare to have all local authorized keys also be authorized by vagrant.
    # Append to ~/.ssh/authorized_keys in shell provision below.
    config.vm.provision "file",
    source: "~/.ssh/authorized_keys",
    destination: "~/.ssh/user_authorized_keys"

    config.vm.provision "shell",
    privileged: true, keep_color: true, inline: <<-SHELL
    export LANGUAGE=en_US.UTF-8
    export LANG=$LANGUAGE
    export LC_ALL=$LANGUAGE
    export DEBIAN_FRONTEND=noninteractive
    locale-gen $LANGUAGE
    update-locale LANGUAGE=$LANGUAGE
    update-locale LANG=$LANG
    update-locale LC_ALL=$LC_ALL
    dpkg-reconfigure locales
    timedatectl set-timezone America/New_York
    dpkg-reconfigure tzdata
    apt-get update
    apt-get dist-upgrade -y
    apt-get install -y curl screen vim tree zip unzip git-core tig build-essential
    update-alternatives --set editor /usr/bin/vim.basic
    echo Adding additional user authorized keys ...
    sort -u /home/vagrant/.ssh/{user_authorized_keys,authorized_keys} > \
    /tmp/authorized_keys
    mv /tmp/authorized_keys /home/vagrant/.ssh/authorized_keys
    SHELL
    end
  8. rduplain created this gist Nov 8, 2019.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    _@rduplain is typing_