Ossian Story
article thumbnail

[VAGRANT & ANSIBLE] Windows Ansible WinRM 환경 구성




VAGRANT & ANSIBLE Windows WinRM 환경 구성


이번 포스팅은 아래의 구성도와 같이 Vagrant로 VM을 Provisioning하고 난 뒤 Ansible을 통해 Windows Client의 Winrm 설정을 하는 방법에 대해 알아보도록 하겠습니다.


[ Vagrant 기초 사용 방법 ]


1. [Vagrant] 설치 및 기초 사용방법 - Windows

2. [Vagrant] vagrantfile 기초 작성 방법



[ Ansible 기초 사용 방법 ]


1. [Ansible] Install - CentOS 7.x

2. [Ansible] ad-hoc 명령어 - CentOS 7.x




WinRM(Windows Remote Management)이란?


Windows 기반 OS 인터페이스에서 사용되는 원격관리 프로토콜입니다. WinRM에서 사용되는 포트는 5985(HTTP), 5986(HTTPS)를 사용하며 Ansible을 통해 Windows Client를 관리하고자 할 경우 WinRM을 통해서 관리 할 수 있습니다.




Windows Server VM Provisioning을 위한 Vagrantfile 작성



[ vagrantfile 작성 내용]


# -*- mode: ruby -*-
# vi: set ft=ruby :
 
vagrant_API_version = "2"
Vagrant.configure(vagrant_API_version) do |config|
 
  # Ansible-Master Setting
  config.vm.define:"ansible-master" do |cfg|
    cfg.vm.box = "centos/7"
    cfg.vm.provider:virtualbox do |vb|
      vb.name = "ansible-master"
      vb.customize ["modifyvm", :id, "--cpus"1]
      vb.customize ["modifyvm", :id, "--memory"512]
    end
    cfg.vm.host_name = "ansible-master"
    cfg.vm.synced_folder ".""/vagrant", disabled: true
    cfg.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", ip: "192.168.0.100"
    cfg.vm.network "forwarded_port", guest: 22, host: 19210, auto_correct: false, id: "ssh"
    cfg.vm.provision "shell", path: "ansible_setup.sh"
    cfg.vm.provision "file", source: "ansible_setting.yml", destination: "ansible_setting.yml"
    cfg.vm.provision "shell", inline: "ansible-playbook ansible_setting.yml"
  end
 
  # Ansible-Winclient Setting
  config.vm.define:"ansible-winclient" do |cfg|
    cfg.vm.box = "opentable/win-2012r2-standard-amd64-nocm"
    cfg.vm.provider:virtualbox do |vb|
      vb.name = "ansible-winclient"
      vb.customize ["modifyvm", :id, "--cpus"2]
      vb.customize ["modifyvm", :id, "--memory"2048]
    end
    cfg.vm.host_name = "ansible-winclient"
    cfg.vm.synced_folder ".""/vagrant", disabled: true
    cfg.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", ip: "192.168.0.101"
    cfg.vm.network "forwarded_port", guest: 22, host: 19211, auto_correct: false, id: "ssh"
    cfg.vm.provision "shell", inline: "netsh firewall set opmode disable" # Windows 방화벽 비 활성화
  end
end




[ ansible_setup.sh 작성 내용]


#! /usr/bin/env bash
 
yum -y install epel-release
yum -y install ansible




[ ansible_setting.yml 작성 내용]


Ansible을 통해 WinRM을 사용할 경우 WinRM에 대한 명시를 해주어야 합니다.

" /etc/ansible/hosts " 파일에 Windows Client에 대하여 "Connection, User, Port" 3가지를 명시하여 WinRM을 사용할 수 있습니다.


---
- name: ansible_setting
  hosts: localhost
  gather_facts: no
  become: yes
 
  tasks:
    - name: add /etc/hosts
      blockinfile: |
        dest=/etc/hosts
        content="
          192.168.0.100 ansible-master
          192.168.0.101 ansible-winclient"
    
    - name: add /etc/ansible/hosts
      blockinfile: |
        dest=/etc/ansible/hosts
        content="
          [win]
          ansible-winclient ansible_connection=winrm ansible_ssh_user=vagrant ansible_ssh_port=5985"
    
    - name: install pip
      yum:
        name: python-pip
        state: latest
    
    - name: install winrm
      pip:
       name: pywinrm
       state: latest





Ansible을 통한 Windows 통신 확인



[ Ansible win_ping  실행 ]


JakeNam-MacPro:Vagrant jake.nam$ vagrant ssh ansible-master
 
[vagrant@ansible-master ~]$ ansible win -m win_ping -k
SSH password: # Password는 vagrant
 
ansible-winclient | SUCCESS => {
    "changed"false
    "ping""pong"
}





profile

Ossian Story

@ossians