

I needed something to test the role for all OSes.
VAGRANT ANSIBLE CODE
As I only use Ubuntu and Archlinux personally I needed to trust contributors that their code works as I couldn’t test the parts that were special for a specific OS. After a while people started contributing code esp. Once nginx is installed, the service can be started using the service module:Īnsible myvagrantbox -b -m service -a "name=nginx state=restarted"Įquivalent of running sudo service nginx restartĪnsibleAnsible is a Python library for managing IT and compute infrastructure.I maintain a small Ansible role for WireGuard. To do that, change the name to name="nginx update_cache=yes":Īnsible myvagrantbox -b -m apt -a name="nginx update_cache=yes"
VAGRANT ANSIBLE UPDATE
IMPORTANT: The first apt module command you give should also run the equivalent of apt-get update before the package is installed.
VAGRANT ANSIBLE INSTALL
Here's how you would install nginx:Īnsible myvagrantbox -b -m apt -a name=nginx The apt module is useful for installing packages. $ ansible myvagrantbox -b -a "tail /var/log/syslog" To run commands that require root access, pass the -b flag to BECOME the root user: If the command has spaces in it, use quotes:Īnsible myvagrantbox -a "tail /var/log/dmesg"

The command module is actually the default module!!! So we don't need to specify -m command, that is the default value: To run a command on the remote machine via ansible:Īnsible myvagrantbox -m command -a uptimeġ7:14:07 up 1:16, 1 user, load average: 0.16, 0.05, 0.04 We can use the command module to run arbitrary commands on the vagrant machines that ansible is managing. We have already seen the -m flag used with ansible to specify an ansible module. Now that the Ansible config file specifies that the inventory file is called hosts, we don't need to specify that with the -i flag anymore: Playbooks/hosts: myvagrantbox ansible_host=127.0.0.1 ansible_port=2222 vagrant/machines/default/virtualbox/private_key To specify default values for SSH key, username, and inventory filename, use this config file: This dir structure allows you to place the config file, plus the playbooks, under version control in a single repo.
VAGRANT ANSIBLE HOW TO
Use the hosts file to tell Ansible how to connect to the (Vagrant) hosts.

Note: for multiple vagrant boxes, see the guide on the Ansible/Full Stack Playbook page.

To clear everything out and destroy all old vagrant boxes:įor info about the ssh configuration of the box: See the Basic Startup and Shutdown Procedure section of the Vagrant page for steps to set up a Vagrant box, and connect to it via SSH.
