jborean93 / ansible-windows

Scripts that are useful for using Ansible with Windows - not affiliated with Ansible in any way
MIT License
211 stars 232 forks source link

Adapt the repository for role testing #11

Closed Daniel-Sanchez-Fabregas closed 5 years ago

Daniel-Sanchez-Fabregas commented 6 years ago

First, Thanks for this repo, very useful for testing.

My use case is windows role testing. I only use two vm (DC + Ansible machine). Could yo add a ansible_stable user with stable versions for ansible and python to the ansible machine?


This is what I'm doing now to use it for role testing:

cd my_role/tests/
git clone https://github.com/jborean93/ansible-windows.git

# Creating windows domain controler and client
cd ansible-windows/vagrant/
vim inventory.yml # Comment the following:
        # SERVER2008:
        #   ansible_host: 192.168.56.11
        #   vagrant_box: jborean93/WindowsServer2008-x64
        #   opt_domain_join_is_longhorn: yes
        # SERVER2008R2:
        #   ansible_host: 192.168.56.12
        #   vagrant_box: jborean93/WindowsServer2008R2
        # SERVER2012:
        #   ansible_host: 192.168.56.13
        #   vagrant_box: jborean93/WindowsServer2012
        # SERVER2012R2:
        #   ansible_host: 192.168.56.14
        #   vagrant_box: jborean93/WindowsServer2012R2
pip install --upgrade --user pywinrm
vagrant plugin install winrm winrm-fs winrm-elevated # Needed in Fedora28
vagrant up
vagrant halt
vagrant snapshot save "snapshot_$(date -Is)"
vagrant up dc # If only dc is needed (my case)

# Creating linux domain client
cd ../vagrant-linux/
vim inventory.yml # Comment the following:
        # UBUNTU1604:
        #   ansible_host: 192.168.56.21
        #   ansible_python_interpreter: /usr/bin/python3
        #   vagrant_box: ubuntu/xenial64
        #   ansible_package_name: 'apt'
        # CENTOS7:
        #   ansible_host: 192.168.56.22
        #   vagrant_box: centos/7
        #   ansible_package_name: 'yum'
vim main.yml  # Comment python and ansible roles

vagrant up

vim Vagrantfile  # Add the following synced folder before the last "end"
# config.vm.synced_folder "../../..", "/home/ansible/my_role", owner: "ansible", group: "ansible-admin"

vagrant halt
vagrant snapshot save "snapshot_$(date -Is)"
vagrant reload

# Setup done. Launch tests
vagrant ssh
sudo -u ansible -i
pip install --upgrade ansible --user
sudo dnf -y install sshpass python2-pexpect
sudo systemctl disable networkmanager
sudo systemctl mask networkmanager
sudo sh -c 'echo "192.168.56.10   dc01.domain.local dc01" >> /etc/hosts'
sudo sh -c 'echo "
search domain.local
nameserver 192.168.56.10
nameserver 10.180.188.75
" > /etc/resolv.conf'

cd ~/my_role/tests/
ansible-playbook main.yml -i inventory.yml