Skip to content

Commit

Permalink
Merge branch 'release-2.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
coglinev3 committed Mar 2, 2020
2 parents 0411928 + 735b9cf commit 4fc2126
Show file tree
Hide file tree
Showing 14 changed files with 374 additions and 211 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Release 2.4.0

* Added new feature 'dynamic_inventory' to automaticaly create the Ansible
inventory file

# Release 2.3.0

* Added Fedora 30
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ playbooks and roles.

## Version

Release: 2.3.0
Release: 2.4.0


## License
Expand All @@ -129,4 +129,4 @@ GPLv3

## Author Information

This Vagrant environment was created in 2019 by Cogline.v3.
This Vagrant environment was created in 2020 by Cogline.v3.
71 changes: 49 additions & 22 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ ENV["LANG"] = "C"

Vagrant.configure(2) do |config|

if current_config['dynamic_inventory']
# define dynamic inventory file
ANSIBLE_INVENTORY_FILE = "provisioning/vagrant.ini"

# create or overwrite inventory file
File.open("#{ANSIBLE_INVENTORY_FILE}" ,'w') do | f |
f.write "[management_node]\nlocalhost ansible_connection=local ansible_host=127.0.0.1\n"
f.write "\n"
f.write "[nodes]\n"
end
else
ANSIBLE_INVENTORY_FILE = "provisioning/inventory.ini"
end

# define the order of providers
config.vm.provider "virtualbox"
config.vm.provider "libvirt"
Expand All @@ -31,22 +45,21 @@ Vagrant.configure(2) do |config|
config.vm.define "#{box['hostname']}#{i}", autostart: box["start"] do |subconfig|
subconfig.vm.box = box["image"]
subconfig.vm.synced_folder ".", "/vagrant", disabled: true
# Configure vbguesṫ auto updates
subconfig.vbguest.auto_update = current_config['vbguest_auto_update']
subconfig.vm.hostname = "#{box['hostname']}#{i}"
subconfig.vm.provider "libvirt" do |libvirt, override|
libvirt.cpus = 1
libvirt.memory = "512"
libvirt.nested = false
end
end # libvirt
subconfig.vm.provider "virtualbox" do |vbox, override|
# Don't install VirtualBox guest additions with vagrant-vbguest
# plugin, because this doesn't work under Alpine Linux
if box["image"] =~ /alpine/
override.vbguest.auto_update = false
override.vm.provision "shell",
inline: "test -e /usr/sbin/dhclient || (echo nameserver 10.0.2.3 > /etc/resolv.conf && apk add --update dhclient)"
end
end # if alpine
vbox.gui = false
vbox.memory = 512
vbox.cpus = 1
Expand All @@ -60,31 +73,41 @@ Vagrant.configure(2) do |config|
if hostname = (vm.ssh_info && vm.ssh_info[:host])
# detect private network ip address on every Linux OS
`vagrant ssh "#{box['hostname']}#{i}" -c "ip addr show eth1|grep -v ':'|egrep -o '([0-9]+\.){3}[0-9]+'"`.split(' ')[0]
end
end
end
subconfig.vm.provision :hostmanager
end # if
end # resolving_vm
end # virtualbox
# The Vagrant timezone configuration doesn't work correctly.
# That's why I use the solution from Frédéric Henri, see: https://stackoverflow.com/questions/33939834/how-to-correct-system-clock-in-vagrant-automatically
# You have to replace 'Europe/Berlin' with the timezone you want to set.
subconfig.vm.provision :shell, :inline => "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime"
end # subconfig

# dynamically create the Ansible inventory file
if current_config['dynamic_inventory']
File.open("#{ANSIBLE_INVENTORY_FILE}" ,'a') do | f |
f.write "#{box['hostname']}#{i} ansible_ssh_private_key_file=/home/vagrant/.ssh/id_rsa.#{box['hostname']}#{i}\n"
end
end

end # each node
end # each box

if current_config['dynamic_inventory']
# finish inventory file
File.open("#{ANSIBLE_INVENTORY_FILE}" ,'a') do | f |
f.write "\n"
f.write "[nodes:vars]\nansible_ssh_user=vagrant\n"
end
end

# Box configuration for Ansible Management Node
config.vm.define "master", primary: true do |subconfig|
subconfig.vm.box = 'centos/7'
subconfig.vm.hostname = "master"
subconfig.hostmanager.ip_resolver = proc do |vm, resolving_vm|
if hostname = (vm.ssh_info && vm.ssh_info[:host])
`vagrant ssh -c "hostname -I"`.split()[1]
end
end
subconfig.vm.provider "libvirt" do |libvirt, override|
libvirt.memory = "1024"
override.vm.synced_folder ".", "/vagrant", type: "nfs"
end
end # libvirt
subconfig.vm.provider "virtualbox" do |vbox, override|
vbox.memory = "1024"
vbox.gui = false
Expand All @@ -97,26 +120,30 @@ Vagrant.configure(2) do |config|
override.hostmanager.ip_resolver = proc do |vm, resolving_vm|
if hostname = (vm.ssh_info && vm.ssh_info[:host])
`vagrant ssh -c "hostname -I"`.split()[1]
end
end
end
subconfig.vm.provision :hostmanager
end # if
end # resolving_vm
end # virtualbox
subconfig.vm.provision :shell, :inline => "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime"
subconfig.vm.provision "ansible_local" do |ansible|
ansible.playbook = "provisioning/bootstrap.yml"
# ansible.provisioning_path = "/vagrant"
ansible.verbose = false
# ansible.vault_password_file = "provisioning/.ansible_vault"
# ansible.ask_vault_pass = true
ansible.limit = "os" # or only "nodes" group, etc.
ansible.limit = "all" # or only "nodes" group, etc.
ansible.install = true
ansible.inventory_path = "provisioning/inventory.ini"
## ansible.inventory_path = "provisioning/inventory.ini"
ansible.inventory_path = "#{ANSIBLE_INVENTORY_FILE}"
# pass environment variable to ansible, for example:
# ANSIBLE_ARGS='--extra-vars "system_update=yes"' vagrant up
ENV["ANSIBLE_ARGS"] = "--extra-vars \"ansible_inventory_file=/vagrant/#{ANSIBLE_INVENTORY_FILE}\""
ansible.raw_arguments = Shellwords.shellsplit(ENV['ANSIBLE_ARGS']) if ENV['ANSIBLE_ARGS']
end
end
end # provision ansible_local
end # subconfig master

# populate /etc/hosts on each node
config.vm.provision :hostmanager

end
end # config

# vim:set nu expandtab ts=2 sw=2 sts=2:
132 changes: 66 additions & 66 deletions boxes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,78 @@
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.

- image: generic/alpine39
start: true
hostname: alpine39-node
vbox_name: 'Alpine 3.9 - Node'
nodes: 1
- image: generic/alpine310
start: true
hostname: alpine310-node
vbox_name: 'Alpine 3.10 - Node'
nodes: 1
- image: centos/6
start: true
hostname: el6-node
vbox_name: 'EL6 - Node'
nodes: 1
- image: centos/7
start: true
hostname: el7-node
vbox_name: 'EL7 - Node'
nodes: 1
#- image: generic/alpine39
# start: true
# hostname: alpine39-node
# vbox_name: 'Alpine 3.9 - Node'
# nodes: 1
#- image: generic/alpine310
# start: true
# hostname: alpine310-node
# vbox_name: 'Alpine 3.10 - Node'
# nodes: 1
#- image: centos/6
# start: true
# hostname: el6-node
# vbox_name: 'EL6 - Node'
# nodes: 1
#- image: centos/7
# start: true
# hostname: el7-node
# vbox_name: 'EL7 - Node'
# nodes: 1
- image: generic/centos8
start: true
hostname: el8-node
vbox_name: 'EL8 - Node'
nodes: 1
- image: generic/debian8
start: true
hostname: debian-jessie-node
vbox_name: 'Debian (Jessie) - Node'
nodes: 1
- image: generic/debian9
start: true
hostname: debian-stretch-node
vbox_name: 'Debian (Stretch) - Node'
nodes: 1
nodes: 2
#- image: generic/debian8
# start: true
# hostname: debian-jessie-node
# vbox_name: 'Debian (Jessie) - Node'
# nodes: 1
#- image: generic/debian9
# start: true
# hostname: debian-stretch-node
# vbox_name: 'Debian (Stretch) - Node'
# nodes: 1
- image: generic/debian10
start: true
hostname: debian-buster-node
vbox_name: 'Debian (Buster) - Node'
nodes: 1
- image: generic/fedora30
start: true
hostname: fedora30-node
vbox_name: 'Fedora 30 - Node'
nodes: 1
- image: generic/fedora31
start: true
hostname: fedora31-node
vbox_name: 'Fedora 31 - Node'
nodes: 1
- image: ubuntu/trusty64
start: true
hostname: ubuntu-trusty-node
vbox_name: 'Ubuntu (Trusty) - Node'
nodes: 1
- image: generic/ubuntu1604
start: true
hostname: ubuntu-xenial-node
vbox_name: 'Ubuntu (Xenial) - Node'
nodes: 1
- image: generic/ubuntu1804
start: true
hostname: ubuntu-bionic-node
vbox_name: 'Ubuntu (Bionic) - Node'
nodes: 1
- image: generic/ubuntu1904
start: true
hostname: ubuntu-disco-node
vbox_name: 'Ubuntu (Disco) - Node'
nodes: 1
- image: generic/ubuntu1910
start: true
hostname: ubuntu-eoan-node
vbox_name: 'Ubuntu (Eoan) - Node'
nodes: 1
#- image: fedora/30-cloud-base
# start: true
# hostname: fedora30-node
# vbox_name: 'Fedora 30 - Node'
# nodes: 1
#- image: fedora/31-cloud-base
# start: true
# hostname: fedora31-node
# vbox_name: 'Fedora 31 - Node'
# nodes: 1
#- image: ubuntu/trusty64
# start: true
# hostname: ubuntu-trusty-node
# vbox_name: 'Ubuntu (Trusty) - Node'
# nodes: 1
#- image: generic/ubuntu1604
# start: true
# hostname: ubuntu-xenial-node
# vbox_name: 'Ubuntu (Xenial) - Node'
# nodes: 1
#- image: generic/ubuntu1804
# start: true
# hostname: ubuntu-bionic-node
# vbox_name: 'Ubuntu (Bionic) - Node'
# nodes: 1
#- image: generic/ubuntu1904
# start: true
# hostname: ubuntu-disco-node
# vbox_name: 'Ubuntu (Disco) - Node'
# nodes: 1
#- image: generic/ubuntu1910
# start: true
# hostname: ubuntu-eoan-node
# vbox_name: 'Ubuntu (Eoan) - Node'
# nodes: 1
2 changes: 2 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ vagrant_config:
hostmanager_manage_host: true
hostmanager_include_offline: true
vbguest_auto_update: true
dynamic_inventory: true
production:
hostmanager_manage_host: false
hostmanager_include_offline: true
vbguest_auto_update: false
dynamic_inventory: true
33 changes: 30 additions & 3 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,33 @@ sudo apt install -y nfs-kernel-server
sudo yum -y install nfs-utils
```

## Define Ansible Client(s)

Your Ansible development environment requires at least one virtual machine
(Vagrant box) with a [supported operating system](/#supported-operating-systems "Supported Operating Systemѕ").
Open the file `boxes.yml` and enter your Ansible clients here, e.g.:

!!! Note "boxes.yml"
```yaml
---
- image: generic/centos8
start: true
hostname: el8-node
vbox_name: 'EL8 - Node'
nodes: 3
- image: generic/debian10
start: true
hostname: debian-buster-node
vbox_name: 'Debian (Buster) - Node'
nodes: 1

```

This will start three nodes with CentOS 8 and one node with Debian Buster. See
section "[Define Vagrant Boxes](/vagrantfile/#define-vagrant-boxes)" for more
details on configuring the `boxes.yml` file.


## Initial Provisioning

The next step will start all Ansible Clients and the Ansible
Expand All @@ -83,15 +110,15 @@ configured provisioners against the running managed machines.
and provisioned in sequence. Then the environment is ready for the
development and testing of new Ansible playbooks and roles.

### Provider VirtualBox
### Provisioning with provider VirtualBox

The Vagrant environment can be started with the provider VirtualBox as follows.

```bash
vagrant up
```

### Provider libvirt
### Provisioning with provider libvirt

If you want to use vagrant with libvirt instead of VirtualBox, use
```bash
Expand All @@ -103,7 +130,7 @@ VAGRANT_DEFAULT_PROVIDER=libvirt vagrant up --no-parallel
in parallel. It happens that Ansible Provisioner is running on the master
node before all Ansible clients are up and running. Therefore, the Ansible
Provisioner sometimes can not reach all clients through SSH from the master
node, and Ansible fails for the affected clients. Therefore, when starting
node, and Ansible fails for the affected clients. That's why when starting
the environment for the first time, the parallel installation should be
suppressed using the vagrant option `--no-parallel`.

Expand Down
5 changes: 5 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ environment which represents a real life [Ansible](http://docs.ansible.com/ansib
scenario with one Ansible management node and different Linux OS nodes (Ansible
clients):
![Ansible figure](ansible_figure.svg)

## Supported Operating Systems

The supported clients are:

* Alpine 3.9,
Expand All @@ -24,6 +27,8 @@ The supported clients are:
* Ubuntu 19.10 (Eoan Ermine).


## Purpose

It is desigend for developing and testing Ansible playbooks and roles on
these operating systems. The configuration can be easily changed to support
other Linux distributions as well. As Vagrant provider (Hypervisors) [VirtualBox](provider/virtualbox.md "VirtualBox")
Expand Down

0 comments on commit 4fc2126

Please sign in to comment.