Ansible development environment to build

ansible automated operation and maintenance tools emerging, based on Python development, a collection of many advantages of operation and maintenance tools (puppet, cfengine, chef, func, fabric) to achieve a batch system configuration, batch deployment, batch run command functions.

  • Building step
    a, creating a virtual machine
    1, the installation VirtualBox
    2, Vagrant installation
    . 3, using the virtual machine installation configuration Vagrant
    II Ansible installed in the virtual machine
    1, the installation Ansible
    Third, the installation Code VS
    1, mounted Visual Studio Code

The build environment for win10

First, create a virtual machine

1, install VirtualBox

  • 1.1 installation package download this virtual machine is to use
    Vargrant created, based on VirtualBox, then download the installation package, has been installed you can click on Next, a shortcut icon will chart a successful installation in a desktop build
    Ansible development environment to build
  • 1.2 After the installation is complete, open the VirtualBox software, open management "global settings, change the default location of the virtual computer to another disk, do not put the C drive
    Ansible development environment to build
    Ansible development environment to build

2, install Vagrant

  • 2.1 Download the installation package , double-click, click Next, after the installation is successful, the CMD command line input
    vagrant version, the following figure represents the successful installation
    Ansible development environment to build
  • 2.2 Installation vbguest plug-in, the command:

    vagrant plugin install vagrant-vbguest

    Ansible development environment to build

  • 2.3 Vagrant command Detailed
command effect
vagrant box add Add box operation
vagrant init Initialization box operation, will generate a configuration file Vagrantfile vagrant
vagrant up Start the local environment
vagrant ssh Ssh login by the local environment where virtual machines
vagrant halt Close the local environment
vagrant suspend Pause the local environment
vagrant resume 恢复本地环境
vagrant reload 修改了Vagrantfile后,使之生效(相当于先 halt,再 up)
vagrant destroy 彻底移除本地环境
vagrant box list 显示当前已经添加的box列表
vagrant box remove 删除相应的box
vagrant package 打包命令,可以把当前的运行的虚拟机环境进行打包
vagrant plugin 用于安装卸载插件
vagrant status 获取当前虚拟机的状态
vagrant global-status 显示当前用户Vagrant的所有环境状态

3、使用Vagrant安装配置虚拟机

  • 3.1 添加box命令:

接下来,我们需要选择使用何种操作系统,这里以ubuntu12.04.5为例。以前基于虚拟机的工作流,我们需要下载ISO镜像,安装系统,设置系统等操作。而Vagrant开源社区提供了许多已经打包好的操作系统,我们称之为box。你可以在网上下载,找到你想要的box,当然你也可以自己制作一个

vagrant box add ubuntu/precise64

Ansible development environment to build
ubuntu/precise64就是下载的box镜像名称

  • 3.2 初始化虚拟机

    vagrant init  ubuntu/precise64

    Ansible development environment to build

    • 3.2.1初始化完成之后,会在当前目录生成Vagrantfile文件,如下所示
      Ansible development environment to build
  • 3.3 启动虚拟机
    vagrant up
    Ansible development environment to build

  • 3.4 进入虚拟机
    vagrant ssh
    Ansible development environment to build

  • 3.5 打包Box

    • 3.5.1、打包完成后会在当前目录生成一个Ubuntu12_04.box的文件,将这个文件分发给其他用户(开发者),其他用户只要添加这个 box ,并用其初始化自己的开发目录,就能得到一个一模一样的开发环境了。
    • 3.5.2、首先要执行exit退出虚拟机界面
      Ansible development environment to build
    • 3.5.3、然后执行 vagrant halt 关闭Ubuntu系统
      Ansible development environment to build
    • 3.5.4、执行vagrant status 确认Ubuntu已经关机
      Ansible development environment to build
    • 3.5.5, execute the command to package, package to complete, will generate a file in the current directory Ubuntu12_04.box

      vagrant package  --output  Ubuntu12_04.box

      Ansible development environment to build
      Ansible development environment to build

    • 3.5.6, if other colleagues need to use the virtual machine, you only need to do the following, this demonstration, demo use another directory, the command is to pack the box before added to the local environment, first of all execute the command:
      vagrant box add Ubuntu12_04  Ubuntu12_04.box   

    Ansible development environment to build

    • 3.5.6.1 then initialize the imported virtual machine, if the current directory has been created Vagrantfile file, you want to change a directory, we use D: \ VS1 directory, initialization commands:
vagrant init Ubuntu12_04  

Ansible development environment to build

  • 3.5.6.2 start the virtual machine
    vagrant up

Ansible development environment to build

Second, the virtual machine installation Ansible

1, the installation Ansible

  • 1.1 Download pip installation package, the following command:
    curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

    Ansible development environment to build

  • 1.2 pip python command to install command, default system python has been installed, the installation command as follows:
    sudo python get-pip.py

    Ansible development environment to build
    Use pip --version to see if the installation was successful
    Ansible development environment to build

  • 1.3 pip then use the command to install ansible, first of all to switch to the root user privileges to prevent all kinds of problems reported
    su - root and then enter the root password, the default password is vagrant
    Ansible development environment to build
  • 1.4 installation command execution ansible
    pip install ansible==2.7.1 --trusted-host mirrors.aliyun.com --index-url=http://mirrors.aliyun.com/pypi/simple/

    Ansible development environment to build

  • 1.5 After the installation is complete, enter ansible --version command to see if success
    Ansible development environment to build

Third, the installation Code VS
1, download the installation package , click Next has been installed, after the installation is successful, the icon will appear Desktop
Ansible development environment to build
2, the installation is complete, enter the main interface, shortcut keys ctrl + shift + x into the resource extension page, enter the language , install the Chinese Simplified, easy to use the software, the installation is complete you need to restart
Ansible development environment to build
3, click on the file "New file, enter the code
Ansible development environment to build
4, mouse click editor, and press F5 to debug
Ansible development environment to build
5, you can click the settings button, add a different debug configuration, such as js, c ++
Ansible development environment to build
Ansible development environment to build

Guess you like

Origin blog.51cto.com/6183574/2420682