Skip to content

Instantly share code, notes, and snippets.

@maxivak
Last active June 8, 2022 06:19
Show Gist options
  • Select an option

  • Save maxivak/c318fd085231b9ab934e631401c876b1 to your computer and use it in GitHub Desktop.

Select an option

Save maxivak/c318fd085231b9ab934e631401c876b1 to your computer and use it in GitHub Desktop.

Revisions

  1. maxivak revised this gist May 12, 2016. 1 changed file with 17 additions and 4 deletions.
    21 changes: 17 additions & 4 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -101,7 +101,7 @@ sudo apt-get install python

    # Setup VM

    ## Ansible playbook.yml
    ## Provision with Ansible


    * Vagrantfile
    @@ -154,11 +154,24 @@ end
    ## hostname


    * Ansible `playbook.yml`

    ```
    ---
    - hosts: all
    tasks:
    # base
    # - hostname: name={{hostname}}
    - lineinfile: dest=/etc/hosts regexp='ubuntu-xenial' line='127.0.0.1 ubuntu-xenial' state=present
    - lineinfile: dest=/etc/hosts regexp='{{hostname}}' line='127.0.0.1 {{hostname}}' state=present
    - shell: sudo bash -c 'hostnamectl set-hostname {{hostname}}'
    ```

    ## Setup network

    * we will use our new box
    * And we will use Ansible to provision VM



    ### Static IP
    * we will add a new interface 'eth1' with static IP
  2. maxivak revised this gist May 12, 2016. 1 changed file with 96 additions and 0 deletions.
    96 changes: 96 additions & 0 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -101,6 +101,56 @@ sudo apt-get install python

    # Setup VM

    ## Ansible playbook.yml


    * Vagrantfile

    ```
    Vagrant.configure(2) do |config|
    ...
    config.vm.provider "virtualbox" do |vb|
    # # Display the VirtualBox GUI when booting the machine
    # vb.gui = true
    #
    # # Customize the amount of memory on the VM:
    vb.memory = "1524"
    end
    config.vm.provision "ansible" do |p|
    p.playbook = "playbook.yml"
    p.verbose = true
    p.extra_vars =
    {
    var1: "value1",
    ..
    }
    end
    end
    ```

    * Ansible `playbook.yml`


    ```
    ---
    - hosts: all
    sudo: true
    tasks:
    # tasks here
    ```



    ## hostname


    @@ -113,6 +163,7 @@ sudo apt-get install python
    ### Static IP
    * we will add a new interface 'eth1' with static IP


    * Vagrantfile

    ```
    @@ -151,10 +202,55 @@ Vagrant.configure(2) do |config|
    end
    end
    ```


    * Ansible playbook `playbook.yml`

    ```
    ---
    - hosts: all
    sudo: true
    tasks:
    # base
    # - hostname: name={{hostname}}
    - lineinfile: dest=/etc/hosts regexp='ubuntu-xenial' line='127.0.0.1 ubuntu-xenial' state=present
    - lineinfile: dest=/etc/hosts regexp='{{hostname}}' line='127.0.0.1 {{hostname}}' state=present
    - shell: sudo bash -c 'hostnamectl set-hostname {{hostname}}'
    # eth
    - name: stop eth1
    shell: ifdown eth1
    ignore_errors: yes
    - name: set networking
    template: src="files/interfaces/eth1.cfg.j2" dest="/etc/network/interfaces.d/eth1.cfg"
    - name: start interface
    #shell: ifup eth1 && ifdown eth1 && ifup eth1
    shell: ifup eth1
    ignore_errors: yes
    - name: restart interface
    shell: sudo ifconfig eth1 up && sudo ifconfig eth1 down && sudo ifconfig eth1 up
    ```

    * template file for eth1.cfg `files/interfaces/eth1.cfg.j2`

    ```
    auto eth1
    iface eth1 inet static
    address {{public_ip}}
    netmask {{public_mask}}
    {% if public_gateway is defined %}gateway {{public_gateway}} {% endif %}
    ```



  3. maxivak revised this gist May 12, 2016. 1 changed file with 1 addition and 31 deletions.
    32 changes: 1 addition & 31 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -97,36 +97,6 @@ sudo apt-get install python
    ```


    ### Create new box

    * commit the box

    ```
    vagrant package
    ```

    it will create *.box file in the current directory.

    You can use this box file to add to the local vagrant repository or copy it to another server.

    * add box to Vagrant locally

    ```
    vagrant box add my-ubuntu-1604 file:///d:/path/to/file.box
    ```


    * use new box in Vagrantfile

    ```
    Vagrant.configure(2) do |config|
    config.vm.box = "my-ubuntu-1604"
    ..
    end
    ```


    # Setup VM
    @@ -154,7 +124,7 @@ NETWORK_GATEWAY = "51.0.0.1"
    Vagrant.configure(2) do |config|
    config.vm.box = "my-ubuntu-1604"
    ...
    # IP
    config.vm.network "public_network", auto_config: false, :bridge => "eth0", ip: "#{IP}"
  4. maxivak revised this gist May 11, 2016. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -109,6 +109,13 @@ it will create *.box file in the current directory.

    You can use this box file to add to the local vagrant repository or copy it to another server.

    * add box to Vagrant locally

    ```
    vagrant box add my-ubuntu-1604 file:///d:/path/to/file.box
    ```


    * use new box in Vagrantfile

  5. maxivak revised this gist May 11, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -115,7 +115,7 @@ You can use this box file to add to the local vagrant repository or copy it to a
    ```
    Vagrant.configure(2) do |config|
    config.vm.box = "my/ubuntu-xenial64"
    config.vm.box = "my-ubuntu-1604"
    ..
    end
    @@ -129,7 +129,7 @@ end

    ## Setup network

    * we will use our new box with python 2 and renamed interface.
    * we will use our new box
    * And we will use Ansible to provision VM


    @@ -147,7 +147,7 @@ NETWORK_GATEWAY = "51.0.0.1"
    Vagrant.configure(2) do |config|
    config.vm.box = "my/ubuntu-xenial64"
    config.vm.box = "my-ubuntu-1604"
    # IP
    config.vm.network "public_network", auto_config: false, :bridge => "eth0", ip: "#{IP}"
  6. maxivak revised this gist May 11, 2016. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion _readme.md
    Original file line number Diff line number Diff line change
    @@ -55,11 +55,23 @@ This will fix error:

    * login to VM (`vagrant ssh`)

    * add (or modify) line in `/etc/default/grub`
    * add (or modify) lines in `/etc/default/grub`

    ```
    GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0 net.ifnames=0 biosdevname=0 net.ifnames=0 biosdevname=0"
    GRUB_CMDLINE_LINUX=" net.ifnames=0 biosdevname=0"
    ```

    * or update using command:

    ```
    #
    sudo sed -i "s/GRUB_CMDLINE_LINUX_DEFAULT=\"\(.*\)\"/GRUB_CMDLINE_LINUX_DEFAULT=\"\1 net.ifnames=0 biosdevname=0\"/" /etc/default/grub
    sudo sed -i "s/GRUB_CMDLINE_LINUX=\"\(.*\)\"/GRUB_CMDLINE_LINUX=\"\1 net.ifnames=0 biosdevname=0\"/" /etc/default/grub
    ```


    * update

    ```
  7. maxivak revised this gist May 11, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion _readme.md
    Original file line number Diff line number Diff line change
    @@ -53,6 +53,8 @@ This will fix error:

    ### Rename interfaces

    * login to VM (`vagrant ssh`)

    * add (or modify) line in `/etc/default/grub`

    ```
    @@ -67,7 +69,7 @@ sudo update-grub
    * so we will have interface named 'eth1'


    * reboot VM
    * reboot VM from the host

    ```
    vagrant reload
  8. maxivak revised this gist May 11, 2016. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,11 @@ vagrant ssh
    127.0.0.1 ubuntu-xenial
    ```

    This will fix error:

    ```
    "sudo: unable to resolve host ubuntu-xenial
    ```

    ### Rename interfaces

  9. maxivak revised this gist May 11, 2016. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion _readme.md
    Original file line number Diff line number Diff line change
    @@ -81,8 +81,18 @@ sudo apt-get install python

    ### Create new box

    * commit the box

    * user new box in Vagrantfile
    ```
    vagrant package
    ```

    it will create *.box file in the current directory.

    You can use this box file to add to the local vagrant repository or copy it to another server.


    * use new box in Vagrantfile

    ```
    Vagrant.configure(2) do |config|
  10. maxivak revised this gist May 11, 2016. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -82,6 +82,16 @@ sudo apt-get install python
    ### Create new box


    * user new box in Vagrantfile

    ```
    Vagrant.configure(2) do |config|
    config.vm.box = "my/ubuntu-xenial64"
    ..
    end
    ```


    # Setup VM
  11. maxivak revised this gist May 11, 2016. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion _readme.md
    Original file line number Diff line number Diff line change
    @@ -49,9 +49,15 @@ vagrant ssh

    ### Rename interfaces

    * add (or modify) line in `/etc/default/grub`

    ```
    GRUB_CMDLINE_LINUX=" net.ifnames=0 biosdevname=0"
    ```
    sudo sed -i "s/GRUB_CMDLINE_LINUX=\"\(.*\)\"/GRUB_CMDLINE_LINUX=\"\1 net.ifnames=0 biosdevname=0\"/" /etc/default/grub && sudo update-grub
    * update

    ```
    sudo update-grub
    ```

    * so we will have interface named 'eth1'
  12. maxivak revised this gist May 11, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion _readme.md
    Original file line number Diff line number Diff line change
    @@ -50,7 +50,7 @@ vagrant ssh
    ### Rename interfaces

    ```
    sudo sed -i "s/GRUB_CMDLINE_LINUX=\"\(.*\)\"/GRUB_CMDLINE_LINUX_DEFAULT=\"\1 net.ifnames=0 biosdevname=0\"/" /etc/default/grub && sudo update-grub
    sudo sed -i "s/GRUB_CMDLINE_LINUX=\"\(.*\)\"/GRUB_CMDLINE_LINUX=\"\1 net.ifnames=0 biosdevname=0\"/" /etc/default/grub && sudo update-grub
    ```

  13. maxivak revised this gist May 11, 2016. 1 changed file with 74 additions and 0 deletions.
    74 changes: 74 additions & 0 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,15 @@ vagrant up
    vagrant ssh
    ```

    ### Hostname
    * fix hostname in `/etc/hosts`


    ```
    127.0.0.1 ubuntu-xenial
    ```



    ### Rename interfaces

    @@ -48,6 +57,13 @@ sudo sed -i "s/GRUB_CMDLINE_LINUX=\"\(.*\)\"/GRUB_CMDLINE_LINUX_DEFAULT=\"\1 net
    * so we will have interface named 'eth1'


    * reboot VM

    ```
    vagrant reload
    ```


    ### Install python

    * To use Ansible we need to install Python 2
    @@ -62,5 +78,63 @@ sudo apt-get install python



    # Setup VM

    ## hostname


    ## Setup network

    * we will use our new box with python 2 and renamed interface.
    * And we will use Ansible to provision VM


    ### Static IP
    * we will add a new interface 'eth1' with static IP

    * Vagrantfile

    ```
    HOSTNAME = 'debugserver'
    IP = "51.0.99.120"
    NETWORK_MASK = "255.0.0.0"
    NETWORK_GATEWAY = "51.0.0.1"
    Vagrant.configure(2) do |config|
    config.vm.box = "my/ubuntu-xenial64"
    # IP
    config.vm.network "public_network", auto_config: false, :bridge => "eth0", ip: "#{IP}"
    config.vm.provider "virtualbox" do |vb|
    # # Display the VirtualBox GUI when booting the machine
    # vb.gui = true
    #
    # # Customize the amount of memory on the VM:
    vb.memory = "1524"
    end
    config.vm.provision "ansible" do |p|
    p.playbook = "playbook.yml"
    p.verbose = true
    p.extra_vars =
    {
    machine: "main",
    public_ip: IP,
    public_mask: NETWORK_MASK,
    public_gateway: NETWORK_GATEWAY,
    }
    end
    end
    ```







  14. maxivak revised this gist May 11, 2016. 1 changed file with 36 additions and 0 deletions.
    36 changes: 36 additions & 0 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,42 @@ end
    ```

    * run Virtual machine (VM)

    ```
    vagrant up
    ```

    * login to VM

    ```
    vagrant ssh
    ```


    ### Rename interfaces

    ```
    sudo sed -i "s/GRUB_CMDLINE_LINUX=\"\(.*\)\"/GRUB_CMDLINE_LINUX_DEFAULT=\"\1 net.ifnames=0 biosdevname=0\"/" /etc/default/grub && sudo update-grub
    ```

    * so we will have interface named 'eth1'


    ### Install python

    * To use Ansible we need to install Python 2

    ```
    sudo apt-get install python
    ```


    ### Create new box






  15. maxivak revised this gist May 11, 2016. 1 changed file with 30 additions and 1 deletion.
    31 changes: 30 additions & 1 deletion _readme.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,30 @@
    # Setup Ubuntu 16.04 to be used with Vagrant and Virtualbox
    # Setup Ubuntu 16.04 to be used with Vagrant and Virtualbox

    ## Prepare Vagrant box with Ubuntu 16.04

    We will use official box "ubuntu/xenial64" and modify it to work with Vagrant.

    * Vagrantfile

    ```
    Vagrant.configure(2) do |config|
    config.vm.box = "ubuntu/xenial64"
    config.vm.provider "virtualbox" do |vb|
    # # Display the VirtualBox GUI when booting the machine
    # vb.gui = true
    #
    # # Customize the amount of memory on the VM:
    vb.memory = "1524"
    end
    end
    ```




  16. maxivak created this gist May 11, 2016.
    1 change: 1 addition & 0 deletions _readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    # Setup Ubuntu 16.04 to be used with Vagrant and Virtualbox