[vagrant@ansible-server ~]$ vi nginx_install.yml
---
- name: Install nginx on Windows
hosts: windows
gather_facts: no
tasks:
- name: Ensure Chocolatey is installed
win_chocolatey:
name: chocolatey
state: present
- name: Install Nginx with Chocolatey
win_chocolatey:
name: nginx
state: present
- name: Create directory
win_file:
path: C:\nginx
state: directory
- name: Download nginx
win_get_url:
url: http://nginx.org/download/nginx-1.14.0.zip
dest: C:\nginx\nginx-1.14.0.zip
- name: Unzip nginx
win_unzip:
src: C:\nginx\nginx-1.14.0.zip
dest: C:\nginx
delete_archive: yes
- name: Install NSSM
win_chocolatey:
name: nssm
state: present
- name: Download new index.html
win_get_url:
url: https://www.nginx.com
dest: C:\nginx\nginx-1.14.0\html\index.html
- name: Nginx service setup by NSSM
win_nssm:
name: nginx
application: C:\nginx\nginx-1.14.0\nginx.exe
state: present
- name: Restart nginx service
win_service:
name: nginx
state: restarted
[vagrant@ansible-server ~]$ anp nginx_install.yml -k
SSH password:
PLAY [Install nginx on Windows] ****************************************************************************************
TASK [Ensure Chocolatey is installed] **********************************************************************************
[WARNING]: Chocolatey was missing from this system, so it was installed during this task run.
changed: [200.200.200.150]
TASK [Install Nginx with Chocolatey] ***********************************************************************************
changed: [200.200.200.150]
TASK [Create directory] ************************************************************************************************
changed: [200.200.200.150]
TASK [Download nginx] **************************************************************************************************
changed: [200.200.200.150]
TASK [Unzip nginx] *****************************************************************************************************
changed: [200.200.200.150]
TASK [Install NSSM] ****************************************************************************************************
ok: [200.200.200.150]
TASK [Download new index.html] *****************************************************************************************
changed: [200.200.200.150]
TASK [Nginx service setup by NSSM] *************************************************************************************
changed: [200.200.200.150]
TASK [Restart nginx service] *******************************************************************************************
changed: [200.200.200.150]
PLAY RECAP *************************************************************************************************************
200.200.200.150 : ok=9 changed=8 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Vagrantfile
PS D:\vagrant_test> ls
디렉터리: D:\vagrant_test
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2024-03-28 오전 10:07 .vagrant
-a---- 2024-03-28 오후 5:06 235 add_sshd_auth.sh
-a---- 2024-03-29 오전 10:33 2615 ansible_env_ready.yml
-a---- 2024-03-29 오전 10:33 2643 Vagrantfile
PS D:\vagrant_test> cp .\Vagrantfile .\Vagrantfile.bak
PS D:\vagrant_test> ls
디렉터리: D:\vagrant_test
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2024-03-28 오전 10:07 .vagrant
-a---- 2024-03-28 오후 5:06 235 add_sshd_auth.sh
-a---- 2024-03-29 오전 10:33 2615 ansible_env_ready.yml
-a---- 2024-03-29 오전 10:33 2643 Vagrantfile
-a---- 2024-03-29 오전 10:33 2643 Vagrantfile.bak
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Define ansible-node07
config.vm.define "ansible-node01" do |cfg|
cfg.vm.box = "gusztavvargadr/windows-server"
cfg.vm.hostname = "ansible-node01"
cfg.vm.network "public_network", ip: "200.200.200.150"
cfg.vm.network "forwarded_port", guest: 22, host: 60017, auto_correct: true, id: "ssh"
cfg.vm.synced_folder "../data", "/vagrant", disabled: true
cfg.vm.provision "shell", inline: "netsh advfirewall set allprofiles state off"
end
# Define ansible-server
config.vm.define "ansible-server" do |cfg|
cfg.vm.box = "rockylinux/9"
cfg.vm.provider "vmware_workstation" do |vb|
# Note: `vb.vmx["sched.cpu.max"] = "50"` might not be necessary or correct for all setups.
vb.vmx["sched.cpu.max"] = "50"
vb.cpus = 2
vb.memory = 3000
vb.gui = true
# The `vb.allowlist_verified` property might not be recognized. Commented out for safety.
# vb.allowlist_verified = true
end
cfg.vm.hostname = "ansible-server"
cfg.vm.network "public_network", ip: "200.200.200.146"
cfg.vm.network "forwarded_port", guest: 22, host: 60010, auto_correct: true, id: "ssh"
cfg.vm.synced_folder "../data", "/vagrant", disabled: true
# Provisioning
cfg.vm.provision "shell", inline: <<-SHELL
dnf install epel-release -y
dnf install ansible -y
dnf install net-tools -y
SHELL
cfg.vm.provision "file", source: "ansible_env_ready.yml", destination: "ansible_env_ready.yml"
cfg.vm.provision "shell", inline: "ansible-playbook ansible_env_ready.yml"
cfg.vm.provision "shell", path: "add_sshd_auth.sh", privileged: false
end
end
---
- name: Setup for the Ansible's Environment
hosts: localhost
gather_facts: no
tasks:
- name: Add "/etc/ansible/hosts"
blockinfile:
path: /etc/ansible/hosts
block: |
[rocky]
200.200.200.147
200.200.200.148
[windows]
200.200.200.150 ansible_connection=winrm ansible_user=vagrant ansible_port=5985
- name: Install epel-release
yum:
name: epel-release
state: present
- name: Install pip
yum:
name: python-pip
state: present
- name: Install pywinrm
pip:
name: pywinrm
state: present
- name: Install sshpass for Authentication
yum:
name: sshpass
state: present
- name: Create vim env's directories & files
shell: "{{ item }}"
with_items:
- "mkdir -p /home/vagrant/.vim/autoload /home/vagrant/.vim/bundle"
- "touch /home/vagrant/.vimrc"
- "touch /home/vagrant/.bashrc"
- name: Install vim-enhanced
yum:
name: vim-enhanced
state: present
- name: Install git
yum:
name: git
state: present
- name: Download pathogen.vim
shell: "curl -fLo /home/vagrant/.vim/autoload/pathogen.vim
https://tpo.pe/pathogen.vim"
- name: Git clone vim-ansible-yaml
git:
repo: https://github.com/chase/vim-ansible-yaml.git
dest: /home/vagrant/.vim/bundle/vim-ansible-yaml
- name: Configure vimrc
lineinfile:
path: /home/vagrant/.vimrc
line: "{{ item }}"
with_items:
- "set number"
- "execute pathogen#infect()"
- "syntax on"
- name: Configure Bashrc
lineinfile:
path: /home/vagrant/.bashrc
line: "{{ item }}"
with_items:
- "alias ans='ansible'"
- "alias anp='ansible-playbook'"
S D:\vagrant_test> vagrant up
--test
S D:\vagrant_test> vagrant status
Current machine states:
ansible-node01 running (vmware_desktop)
ansible-server running (vmware_workstation)
This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.
PS D:\vagrant_test>
PS D:\vagrant_test>
PS D:\vagrant_test> vagrant box list
gusztavvargadr/windows-server (vmware_desktop, 2102.0.2402, (amd64))
rockylinux/9 (vmware_desktop, 3.0.0, (amd64))
node01 window 넣어주기
C:\Users\vagrant>ipconfig
Windows IP Configuration
Ethernet adapter Ethernet1:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::ed38:e180:2a91:d131%5
IPv4 Address. . . . . . . . . . . : 200.200.200.150
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Ethernet adapter Ethernet0:
Connection-specific DNS Suffix . : localdomain
Link-local IPv6 Address . . . . . : fe80::c471:e081:35ca:c880%6
IPv4 Address. . . . . . . . . . . : 172.16.0.52
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 172.16.0.254
C:\Users\vagrant>ping 200.200.200.146
Pinging 200.200.200.146 with 32 bytes of data:
Reply from 200.200.200.146: bytes=32 time<1ms TTL=64
Reply from 200.200.200.146: bytes=32 time<1ms TTL=64
Reply from 200.200.200.146: bytes=32 time<1ms TTL=64
Ping statistics for 200.200.200.146:
Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
[vagrant@ansible-server ~]$ vi nginx_install.yml
---
- name: Install nginx on Windows
hosts: windows
gather_facts: no
tasks:
- name: Ensure Chocolatey is installed
win_chocolatey:
name: chocolatey
state: present
- name: Install Nginx with Chocolatey
win_chocolatey:
name: nginx
state: present
- name: Create directory
win_file:
path: C:\nginx
state: directory
- name: Download nginx
win_get_url:
url: http://nginx.org/download/nginx-1.14.0.zip
dest: C:\nginx\nginx-1.14.0.zip
- name: Unzip nginx
win_unzip:
src: C:\nginx\nginx-1.14.0.zip
dest: C:\nginx
delete_archive: yes
- name: Install NSSM
win_chocolatey:
name: nssm
state: present
- name: Download new index.html
win_get_url:
url: https://www.nginx.com
dest: C:\nginx\nginx-1.14.0\html\index.html
- name: Nginx service setup by NSSM
win_nssm:
name: nginx
application: C:\nginx\nginx-1.14.0\nginx.exe
state: present
- name: Restart nginx service
win_service:
name: nginx
state: restarted
[vagrant@ansible-server ~]$ anp nginx_install.yml -k
SSH password:
PLAY [Install nginx on Windows] ****************************************************************************************
TASK [Ensure Chocolatey is installed] **********************************************************************************
[WARNING]: Chocolatey was missing from this system, so it was installed during this task run.
changed: [200.200.200.150]
TASK [Install Nginx with Chocolatey] ***********************************************************************************
changed: [200.200.200.150]
TASK [Create directory] ************************************************************************************************
changed: [200.200.200.150]
TASK [Download nginx] **************************************************************************************************
changed: [200.200.200.150]
TASK [Unzip nginx] *****************************************************************************************************
changed: [200.200.200.150]
TASK [Install NSSM] ****************************************************************************************************
ok: [200.200.200.150]
TASK [Download new index.html] *****************************************************************************************
changed: [200.200.200.150]
TASK [Nginx service setup by NSSM] *************************************************************************************
changed: [200.200.200.150]
TASK [Restart nginx service] *******************************************************************************************
changed: [200.200.200.150]
PLAY RECAP *************************************************************************************************************
200.200.200.150 : ok=9 changed=8 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
--vagrant
[vagrant@ansible-server ~]$ ansible windows -m win_shell -a "powershell Get-timezone" -k
SSH password:
200.200.200.150 | CHANGED | rc=0 >>
Id : UTC
DisplayName : (UTC) Coordinated Universal Time
StandardName : Coordinated Universal Time
DaylightName : Coordinated Universal Time
BaseUtcOffset : 00:00:00
SupportsDaylightSavingTime : False
--host
PS C:\Users\user2> powershell Get-timezone
Id : Korea Standard Time
DisplayName : (UTC+09:00) 서울
StandardName : 대한민국 표준시
DaylightName : 대한민국 일광 절약 시간
BaseUtcOffset : 09:00:00
SupportsDaylightSavingTime : False
[vagrant@ansible-server ~]$ vim timezone.yml
---
- name: set up windows timezone
hosts: windows
gather_facts: no
tasks:
- name: set time to Asia/Seoul
win_timezone: timezone='Korea Standard Time'
[vagrant@ansible-server ~]$ anp timezone.yml -k
SSH password:
PLAY [set up windows timezone] *****************************************************************************************
TASK [set time to Asia/Seoul] ******************************************************************************************
changed: [200.200.200.150]
PLAY RECAP *************************************************************************************************************
200.200.200.150 : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[vagrant@ansible-server ~]$ ansible windows -m win_shell -a "powershell Get-timezone" -k
SSH password:
200.200.200.150 | CHANGED | rc=0 >>
Id : Korea Standard Time
DisplayName : (UTC+09:00) Seoul
StandardName : Korea Standard Time
DaylightName : Korea Daylight Time
BaseUtcOffset : 09:00:00
SupportsDaylightSavingTime : False
--nfs.yml
[vagrant@ansible-server ~]$ vi nfs.yml
[vagrant@ansible-server ~]$ anp nfs.yml -k
SSH password:
PLAY [Setup for nfs server] ********************************************************************************************
TASK [make nfs_shared directory] ***************************************************************************************
changed: [localhost]
TASK [configure /etc/exports] ******************************************************************************************
changed: [localhost]
TASK [nfs service restart] *********************************************************************************************
changed: [localhost]
PLAY [Setup for nfs windows clients] ***********************************************************************************
TASK [mount feature on] ************************************************************************************************
changed: [200.200.200.150]
TASK [mount nfs_shared] ************************************************************************************************
client_loop: send disconnect: Connection reset