- Learning Ansible 2.7(Third Edition)
- Fabio Alessandro Locati
- 423字
- 2021-06-24 15:08:40
Creating a test environment with Vagrant
To be able to learn Ansible, we will need to make quite a few playbooks and run them.
It's possible to create a test environment with cloud providers in a few seconds, but it is often more useful to have those machines locally. To do so, we will use Vagrant, which is a piece of software by Hashicorp that allows users to quickly set up virtual environments independently from the virtualization backend used on the local system. It does support many virtualization backends (in the Vagrant ecosystem these are known as Providers) such as Hyper-V, VirtualBox, Docker, VMWare, and libvirt. This allows you to use the same syntax no matter what operating system or environment you are in.
First we will install vagrant. On Fedora, it will be enough to run the following code:
$ sudo dnf install -y vagrant
On Red Hat/CentOS/Scientific Linux/Unbreakable Linux, we will need to install libvirt first, enable it, and then install vagrant from the Hashicorp website:
$ sudo yum install -y qemu-kvm libvirt virt-install bridge-utils libvirt-devel libxslt-devel libxml2-devel libvirt-devel libguestfs-tools-c
$ sudo systemctl enable libvirtd
$ sudo systemctl start libvirtd
$ sudo rpm -Uvh https://releases.hashicorp.com/vagrant/2.2.1/vagrant_2.2.1_x86_64.rpm
$ vagrant plugin install vagrant-libvirt
If you use Ubuntu or Debian, you can install it using the following code:
$ sudo apt install virtualbox vagrant
For the following examples, I'll be virtualizing CentOS 7 machines. This is for multiple reasons; the main ones are as follows:
- CentOS is free and 100% compatible with Red Hat, Scientific Linux, and Unbreakable Linux.
- Many companies use Red Hat/CentOS/Scientific Linux/Unbreakable Linux for their servers.
- These distributions are the only ones with SELinux support built in, and, as we have seen earlier, SELinux can help you make your environment much more secure.
To test that everything went well, we can run the following commands:
$ sudo vagrant init centos/7 && sudo vagrant up
If everything went well, you should expect an output ending with something like this:
==> default: Configuring and enabling network interfaces...
default: SSH address: 192.168.121.60:22
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Rsyncing folder: /tmp/ch01/ => /vagrant
So, you can now execute vagrant ssh, and you will find yourself in the machine we just created.
- 皮膚病中藥內(nèi)用制劑
- MR臨床手冊
- 人體寄生蟲學(xué)實(shí)驗(yàn)與學(xué)習(xí)指導(dǎo)(第2版)
- 成人聽力障礙康復(fù)讀本
- 癌癥療愈錄:腫瘤門診敘事紀(jì)實(shí)
- 眼科手術(shù)器械清洗消毒滅菌技術(shù)操作規(guī)程
- 實(shí)用甲狀腺疾病診療學(xué)
- 臨床醫(yī)學(xué)專業(yè)綜合改革的探索
- Practical PowerShell Security and Compliance Center
- 你的第一本抑郁自救指南
- 老魚頭的麻醉隨筆
- 遺傳性視神經(jīng)病變
- 口腔科常見及多發(fā)病就醫(yī)指南系列:顳下頜關(guān)節(jié)與面痛就醫(yī)指南
- 運(yùn)動(dòng)傷病病理學(xué)
- 社交潛規(guī)則:以孤獨(dú)癥視角解析社交奧秘