未加星标

Using Ansible through Windows 10's Subsystem for Linux

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二04 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

Ever since I heard about the new 'Beta' windows Subsystem for linux, which basically installs an Ubuntu LTS release inside of Windows 10 (currently 14.04), I've been meaning to give it a spin, and see if it can be a worthy replacement for Cygwin, Git shell, Cmder, etc. And what I was most interested in was whether I could finally point people to a more stable and friendly way of using Ansible on a Windows workstation.

In the past, there was the option of running Ansible inside Cygwin (and this is still the best way to try getting Ansible working in an older Windows environment), but this always felt kludgy to me, and I hated having to recommend either that or forcing Windows users to do a full Linux VM installation just to run Ansible commands. I finally updated my PC laptop to the latest Windows 10 Anniversary Update, and installed the Windows Subsystem for Linux, and lo and behold, Ansible works!


Using Ansible through Windows 10's Subsystem for Linux

In this blog post, I'll show you how to install and use Ansible on Windows 10.

Installing Bash on Windows 10

Before installing the Linux Subsystem, you have to have:

Windows 10 (Anniversary update or later version) 64-bit installation (can't run on 32-bit systems)

Once you verify your system is 64-bit and up to date, you have to do a few manual steps to enable the 'Windows Subsystem for Linux':

Open 'Settings' (the cog in the start menu) Click 'Update & Security', then click the 'For developers' option on the left. Toggle the 'Developer mode' option, and accept any warnings Windows pops up.

Wait a minute for Windows to install a few things in the background (it will eventually let you know a restart may be required for changes to take effect―ignore that for now). Next, to install the actual Linux Subsystem, you have to jump over to 'Control Panel' ( why is this separate from 'Settings'? ), and do the following:

Click on 'Programs' Click on 'Turn Windows features on or off' Scroll down and check 'Windows Subsystem for Linux (Beta)', and then click OK.

The subsystem will be installed, then Windows will require a reboot. Reboot, then open up the start menu and enter 'bash' (to open up 'Bash' installation in a new command prompt). Fill out all the questions (it will have you create a separate user account for the Linux subsystem), and once that's all done (it takes a few minutes to install), you will finally have Ubuntu running on your Windows laptop, somewhat integrated with Windows.

Installing Ansible

To install Ansible, since we're basically in an Ubuntu environment, it's as simple as installing pip, then installing Ansible:

Open a bash prompt (from start menu, type 'bash' and hit enter). Install Pip: sudo apt-get -y install pip python-dev Install Ansible: pip install ansible --user ( --user installs packages local to the user account instead of globally to avoid permissions issues with Pip and the Linux Subsystem) Since the ansible* commands are installed under ~/.local/bin , we need to add that to the $PATH, so run the command: echo 'PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc Either exit out of the bash prompt and start it again from the Windows menu, or run source .bashrc to update your $PATH to include Ansible.

Note the use of --user for the pip install command; due to some peculiarities of the way the Linux subsystem works, Pip can't easily install packages globally, so we install packages just for the user account we set up for bash.

Using Ansible

At this point, which ansible should show the path to Ansible, ansible --version should show you Ansible's version, and you should be able to use ansible and the rest of the command-line tools (e.g. ansible-playbook , ansible-galaxy , etc.) as you would on any common environment.

If you get the error message ImportError: No module named markupsafe , try installing markupsafe manually with pip install markupsafe --user . See this GitHub issue for more detail.

If you want to run a playbook that's stored in your Windows user account's Documents folder (e.g. C:\Users\jgeerling\Documents ), you can do so by navigating to /mnt/c/Users/jgeerling/Documents (where jgeerling is your username). Windows drives are mounted in the Subsystem inside the /mnt directory. Let's create a test playbook and see if it works!

Open a bash prompt, and cd into your Windows user's Documents directory: cd /mnt/c/Users/jgeerling/Documents . Create a new test playbook: touch test.yml

User nano or some other editor to add the following contents:

--- - hosts: localhost tasks: - debug: msg="Ansible is working!" Run the playbook with the command ansible-playbook test.yml --connection=local

Ansible should run the command and print out the debug message. Ansible might warn about no inventory file being present, but since you're using --connection=local , the localhost host should automatically work.


Using Ansible through Windows 10's Subsystem for Linux
Going further

Now that you have Ansible installed, you can start automating everything (even including the rest of the bash environment)! If you need to, you can generate an SSH key for use connecting to servers, use ssh to directly connect to servers, etc. It's basically a full Ubuntu LTS install running inside Windows!

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

主题: WindowsLinuxUbuntuGitGitHub
分页:12
转载请注明
本文标题:Using Ansible through Windows 10's Subsystem for Linux
本站链接:http://www.codesec.net/view/479677.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(56)