This is repo with complete example for using ansible on Windows 10 WSL with Vagrant. First at all you should install WLS (Ubuntu 18.04), Vagrant for Windows and ansible in WLS. After that you can use deploy on vagrant box for local testing prod and deploy to VPS/VDS prod
-
create vault's file with passwords and put in it your password as plain text
in WSL
ansible-vault create .vault_pass
WARNING!!!: Don't add this file under source control
-
for solve problem that WSL(windows bash) create executable files and don't understand linux permission create wsl.conf from WSL(windows bash) and with linux editor (microsoft/WSL#81)
in WSL
sudo vim /etc/wsl.conf
File content
[automount] enabled = true options = "metadata" mountFsTab = false
Restart WSL(windows bash)
-
Create file
ansible.cfg
and add path to vault_pass filein WSL
[defaults] vault_password_file = ./.vault_pass
-
Create file
secrets.yml
with all secrets password and vars for this project.in WSL
ansible-vault create secrets.yml
This file be encrypted, you can edit it with vi from ansible-vault commands. Content should looks like
password: 12345678 password2: 12345678 ...
You can use this content in other files with names {{ password }}, {{ password2 }} and etc.
-
Create file
vars.yml
with all vars for this project.File vars.yml for example
-
Create file
vagrant_hosts.yml
with project hosts.File vagrant_hosts.yml for example
-
Create file
vagrant_prepare.yml
with istructions for first settings server (create user, ssh and etc.)File vagrant_prepare.yml for example
-
Create file
vagrant_deploy.yml
File vagrant_deploy.yml for example
-
Create Vargant file with needed for you options adn add forwarded port 80 to 8080
Vagrant.configure("2") do |config| config.vm.box = "centos/7" config.vm.synced_folder ".", "/vagrant", disabled: true config.vm.network "forwarded_port", guest: 80, host: 8080 end
-
Start you VM
in Git-Bash (or windows shell)
vargant up
-
Getting SSH keys on the VMs. You need first delete
~/.ssh
in WLS, then linked it with you Windows ssh key, change you persmission for VM private key in.vagrant/machines/default/virtualbox
right 600 from default WLS 777.in WSL
rm -R ~/.ssh ln -s /mnt/c/Users/akalightowl/.ssh ~/.ssh chmod 600 /mnt/c/Users/akalightowl/WORK/otlservice-ru/deploy/.vagrant/machines/default/virtualbox/private_key ssh -i /mnt/c/Users/akalightowl/WORK/otlservice-ru/deploy/.vagrant/machines/default/virtualbox/private_key -o PasswordAuthentication=no vagrant@127.0.0.1 -p 2222
-
Prepare server
in WSL
ansible-playbook -i vagrant_hosts vagrant_prepare.yml
-
Deploy
in WSL
ansible-playbook -i vagrant_hosts vagrant_deploy.yml
-
Create file
prod_hosts_root.yml
.File prod_hosts_root.yml for example
-
Create file
prod_hosts_user.yml
.File prod_hosts_user.yml for example
-
Create file
prod_prepare.yml
with istructions for first settings server (create user, ssh and etc.)File prod_prepare.yml for example
-
Create file
prod_deploy.yml
with instructions for deploy after adding changes to project.File prod_deploy.yml for example
-
Copy your ssh public key to prod server.
in WSL
ssh-copy-id -i ~/.ssh/id_rsa.pub root@youServerIp
-
Create project user on production server
in WSL
ansible-playbook -i prod_hosts_root prod_create_user.yml
-
Prepare production server
in WSL
ansible-playbook -i prod_hosts_user prod_prepare.yml
-
Deploy
in WSL
ansible-playbook -i prod_hosts_user prod_deploy.yml