Skip to content

Commit

Permalink
refact(puppet): use vagrant plugin to manage hosts file configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
wikitops committed May 29, 2020
1 parent 9f33aae commit 5d56d4b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ What things you need to run this Ansible playbook :
* [Vagrant](https://www.vagrantup.com/docs/installation/) must be installed on your computer
* Update the Vagrant file based on your computer (CPU, memory), if needed
* Update the operating system to deploy in the Vagrant file (default: Ubuntu)
* Install the [Vagrant HostManager plugin](https://github.com/devopsgroup-io/vagrant-hostmanager) :

```
$ vagrant plugin install vagrant-hostmanager
```
* Download the Ansible requirements:

```bash
Expand Down Expand Up @@ -42,6 +47,7 @@ Current machine states:

puppet01 running (virtualbox)
puppet02 running (virtualbox)
puppet03 running (virtualbox)
```

If everything run as expected, you should have Puppet installed and configured on the Vagrant instance.
Expand Down
9 changes: 8 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SUPPORTED_OS = {

# Vagrant instance management
$os = "centos"
$num_instances = 2
$num_instances = 3
$instance_name_prefix = "puppet"
$vm_memory = 2048
$vm_cpus = 2
Expand Down Expand Up @@ -38,6 +38,13 @@ end

Vagrant.configure("2") do |config|

# Configure hosts file
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.manage_guest = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true

# always use Vagrants insecure key
config.ssh.insert_key = false
config.ssh.username = SUPPORTED_OS[$os][:user]
Expand Down
6 changes: 0 additions & 6 deletions roles/puppet/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
- name: PUPPET | Include OS-specific variables
include_vars: "{{ ansible_os_family }}.yml"

- name: PUPPET | Configure hosts file
lineinfile:
path: /etc/hosts
line: "{{ hostvars[item]['ip'] }} {{ item }}"
loop: "{{ groups['puppet_server'] }}"

- name: PUPPET | Include OS-specific tasks
include_tasks: "{{ ansible_os_family }}.yml"

Expand Down

0 comments on commit 5d56d4b

Please sign in to comment.