Howto Provision Vagrant Virtual Machines with Ansible



Let’s show how great Ansible is to provision vagrant virtual machines. On my MacOS host Inhave Vagrant from HashiCorp installed along with VirtualBox an Ansible. We will first look at using Vagrant before seeing how Ansible Playbook and really provision your VM and easily.

The Playbook is copied below:


– name: test
hosts: all
gather_facts: true
become: true
handlers:
– name: restart_sshd
service:
name: sshd
state: restarted
tasks:
– name: install
package:
state: latest
name:
– bash-completion
– vim
– nano
– name: Create tux user
user:
name: tux
state: present
password: “{{ ‘Password1’ | password_hash(‘sha512’) }}”
update_password: on_create
shell: /bin/bash
– name: Edit SSHD Config
lineinfile:
path: /etc/ssh/sshd_config
regexp: ‘^PasswordAuthentication ‘
insertafter: ‘#PasswordAuthentication’
line: ‘PasswordAuthentication yes’
notify: restart_sshd
– name: Add sudo rights for tux
copy:
dest: /etc/sudoers.d/tux
content: “tux ALL=(root) NOPASSWD: ALL”
backup: true

and take time to see my own site

source

14 thoughts on “Howto Provision Vagrant Virtual Machines with Ansible”

Leave a Reply

Your email address will not be published.

Captcha loading...