Windows 10和ubuntu 20 04工作站的Ansible本地自动化入门

You don’t need to be a seasoned DevOps professional to benefit from Ansible and related automation tools in your personal workspace. I will show an example setup I use to automate my personal Windows 10 and Ubuntu 20.04 workstation configuration (a similar approach would also work for MacOS).

您无需成为经验丰富的DevOps专业人员,即可从您个人工作区中的Ansible及相关自动化工具中受益。 我将显示一个示例设置,该设置用于自动化个人Windows 10和Ubuntu 20.04工作站配置(类似的方法也适用于MacOS)。

The main goal of this setup is automating software installation, updates and configuration to quickly get my development environment running on both Ubuntu and Windows, so the system can be recreated effortlessly in case of stability issues or when switching to a new machine, taking less than an hour to setup each OS with the essentials to be ready for work. The key tools that will come in handy (besides Ansible) will be Snap (for Linux packages), Mackup (for Linux dotfiles/configuration backup) and Chocolatey (for Windows packages).

此设置的主要目标是自动化软件安装,更新和配置,以快速使我的开发环境在Ubuntu和Windows上运行,因此,在出现稳定性问题或切换到新计算机时,可以轻松地重新创建系统,而花费的时间少于一个小时来设置每个OS所需的基本知识,以准备工作。 方便使用的关键工具(Ansible除外)将是Snap (对于Linux软件包), Mackup (对于Linux点文件/配置备份)和Chocolatey (对于Windows软件包)。

I will be installing VSCode, git, Node.js (nvm), Docker, Chromium, Slack and Dropbox on both systems.

我将在两个系统上安装VSCode,git,Node.js(nvm),Docker,Chromium,Slack和Dropbox。

配置Windows 10 (Configuring Windows 10)

First I run the following script in cmd to setup WinRM for Ansible:powershell.exe -ExecutionPolicy ByPass -File "windows-host-setup.ps1"

首先,我在cmd中运行以下脚本来为Ansible设置WinRM: powershell.exe -ExecutionPolicy ByPass -File "windows-host-setup.ps1"

Then, to execute my Ansible playbook on Windows I need a running Ansible control node which requires a Linux environment and the simplest way to get that running on the same machine is Windows Subsystem for Linux (WSL).

然后,要在Windows上执行我的Ansible剧本,我需要一个正在运行的Ansible控制节点,该节点需要一个Linux环境,要使它在同一台机器上运行,最简单的方法是Windows Subsystem for Linux(WSL)。

Windows Linux子系统 (Windows Subsystem for Linux)

  1. Windows search for Turn Windows features on or off, check Windows Subsystem for Linux, install, reboot;

    Windows搜索Turn Windows features on or off ,检查Windows Subsystem for Linux ,安装,重新启动;

  2. Install and launch Ubuntu 20.04 from the Windows Store;

    从Windows应用商店安装并启动Ubuntu 20.04;
  3. Create a user with password;

    用密码创建一个用户;
  4. Install Ansible: sudo apt update && sudo apt install -y ansible

    安装Ansible: sudo apt update && sudo apt install -y ansible

  5. Run the Windows playbook: ansible-playbook windows-playbook.yml -i windows-inventory.yml --ask-pass --verbose

    运行Windows剧本: ansible-playbook windows-playbook.yml -i windows-inventory.yml --ask-pass --verbose

As evident above, I use Chocolatey to install software packages that will then auto-update. Finally, I install VSCode Settings Sync to restore my VSCode settings.

如上所示,我使用Chocolatey安装了软件包,然后将它们自动更新。 最后,我安装VSCode Settings Sync来还原我的VSCode设置。

配置Ubuntu 20.04 (Configuring Ubuntu 20.04)

I prefer snap packages (which auto-update and roll back gracefully) over apt packages, when available. The following works on Ubuntu 20.04:

与apt软件包(如果可用)相比,我更喜欢snap软件包(可自动更新并回滚)。 以下在Ubuntu 20.04上有效:

  1. Install Ansible: sudo apt update && sudo apt install -y ansible

    安装Ansible: sudo apt update && sudo apt install -y ansible

  2. Run the Ubuntu playbook: ansible-playbook ubuntu-playbook.yml -i ubuntu-inventory.yml --ask-become-pass --verbose

    运行Ubuntu剧本: ansible-playbook ubuntu-playbook.yml -i ubuntu-inventory.yml --ask-become-pass --verbose

Then I run Dropbox, wait for it to sync and run mackup restore to restore configuration files previously backed up to Dropbox with mackup backup. Finally, install and run VSCode Settings Sync as before.

然后,我运行Dropbox,等待它同步并运行mackup restore以还原以前使用mackup backup到Dropbox的配置文件。 最后,像以前一样安装并运行VSCode Settings Sync。

而已! (That’s it!)

Some manual steps will always remain but overall this approach saves a lot of time once it’s part of your toolbelt. Many more parts of system configuration can be automated, see list of Ansible modules for inspiration and feel free to fork and extend my example gists for your own use! :)

某些手动步骤将始终保留,但是总的来说,这种方法一旦成为工具带的一部分,便可以节省大量时间。 系统配置的更多部分可以自动执行,请参见Ansible模块列表以获取灵感,并随意分叉和扩展我的示例要点供您自己使用! :)

翻译自: https://levelup.gitconnected.com/getting-started-with-ansible-local-automation-of-windows-10-and-ubuntu-20-04-workstations-ffd03d7dc923

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值