3/14/2023 0 Comments Vagrant ansibletasks: - All the individual tasks after this line will be run on the hosts.become: yes - We need privileged/sudo access to install the packages.'All' should work fine because Vagrant uses its own inventory file (more on this later) - hosts: all - This tells Ansible to which hosts this Playbook applies.Let's go through the Playbook step-by-step Since Ansible version 2.0, you can install multiple packages using the name attribute. Let's create the Ansible playbook.yml file in the same directory as your Vagrantfile.Ī playbook that installs Ansible, Git, Nmap and net-tools looks like this: The main component of a successful Ansible provisioner setup is the Ansible playbook which contains the steps that should run on the guest. config.vm.provision "ansible" do |ansible| - Configure Ansible as the provisioner.server.vm.network :public_network, ip: "10.10.40.5", :netmask => "255.255.0.0" - Set the network to 'bridged/public-network' mode and assign static IP.server.vm.hostname = "my-server" - Set the hostname to 'my-server'.config.vm.define "my-server" do |server| - Configuration parameters for the VM.config.vm.box = "centos/7" - Vagrant to create CentOS VM.Let's edit the Vagrantfile to create a CentOS 7 VM and use Ansible as the provisioner. You only need two files for this to work, Vagrantfile and the Ansible Playbook, both files should be located in your project folder. You are no longer required to download the ISO from the vendor, boot the ISO from VirtualBox/VMware and then fiddle with various configurations and package installation. Our end goal here is to use Vagrant to create a CentOS 7 VM and then use Ansible to install the required packages (Git, Ansible, Nmap and net-tools) A simple vagrant up will create the VM and the Ansible Playbook will handle the configuration and package installation. When you run vagrant up the first time, Vagrant passes off the VM to whichever provisioner is configured on the Vagrantfile (Ansible in our case) and tells it to run the defined Playbook. The Vagrant Ansible provisioner allows you to provision the guest machine using Ansible playbooks by executing ansible-playbook from the Vagrant host. This blog post focuses on using Ansible as a provisioner. Vagrant supports many provisioners such as Ansible, Salt, Puppet and Chef.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |