LoginSignup
1
0

More than 5 years have passed since last update.

Ubuntu 18.04 on WSL を Ansible でプロビジョニングする

Posted at

Ubuntu 18.04 on WSL 上に Ansible をインストールし、localhostのプロビジョニングを行います

環境

  • Windows10 Home
    • Ubuntu 18.04 on WSL インストールが完了していること

手順

1. 必要なパッケージのインストール

sude apt update
sudo apt install -y python3 python3-pip
pip3 install --user --upgrade ansible setuptools virtualenv

2. Ansible Playbook の作成

playbook その他ファイルを作成します。ファイル階層は以下の通り

ansible/
 ├ hosts
 ├ host_vars/
 │  └ localhost.yaml
 └ playbook.yaml
ansible/hosts
[local]
localhost
ansible/host_vars/localhost.yaml
ansible_python_interpreter: /usr/bin/python3
ansible/playbook.yaml
---
- hosts: local
  connection: local
  tasks:
    - name: apt update/upgrade
      become: yes
      apt:
        autoclean: yes
        autoremove: yes
        cache_valid_time: 3600
        update_cache: yes
        upgrade: safe

ポイントは ansible/playbook.yaml 内の connection: local です。
これにより、プロビジョニングの際に localhost への SSH ログインを行わなくなるため、
Ubuntu on WSL の SSH サーバ起動が不要になります。

3. プロビジョニングの実行

ansible-playbook --ask-become-pass --inventory ansible/hosts ansible/playbook.yaml

おまけ

Ansible のインストールから Playbook の実行までをシェルスクリプトとしてまとめたものを Github で公開しています(Ansible-Vault 対応)
https://github.com/epaew/init.wsl.ubuntu

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0