Razique Mahroua
2020-02-27 9f5643221c161807de83d51d70602de954366ede
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- name: Step 00xxxxx post software
  hosts: localhost
  connection: local
  gather_facts: False
  become: no
  tasks:
    - debug:
        msg: "Post-Software tasks Started"
 
- name: Copy files to workstation
  hosts: workstations
  tasks:
    - name: Copy Ansible Inventory for this environment
      win_copy:
        src: "{{output_dir}}/hosts-{{ env_type }}-{{ guid }}"
        dest: "C:\\inventory.ini"
 
- name: PostSoftware flight-check
  hosts: towers
  gather_facts: false
  become: yes
  tags:
    - post_flight_check
  tasks:
    - name: See if virtualenv is installed
      stat:
        path: venv
      register: virtualenv
 
    - name: Setup python virtualenv
      shell: |
        virtualenv venv
        source venv/bin/activate
        pip install ansible requests-credssp pywinrm
        deactivate
        exit 0
      when: not virtualenv.stat.exists
 
    - name: Test Ansible connectivity to Windows servers
      shell: |
        source venv/bin/activate
        ansible windows -m win_ping
      register: ansible_check
      ignore_errors: true
 
    - debug:
        var: ansible_check
 
    - fail:
        msg: "Ansible test of tower environment failed"
      when: ansible_check is failed
 
    - debug:
        msg: "Post-Software checks completed successfully"
 
- name: Include private workloads
  include_playbook: workloads.yml
  
- name: Provisioning final tasks
  hosts: localhost
  connection: local
  gather_facts: false
  become: no
  tasks:
    - name: Report provisioning status
      include_role:
        name: status-report
      vars:
        classroom_status: "Classroom ready"
        status_json: "{{ lookup('template', 'report.j2') }}"
      when: report_status
    - name: Stop SSH/Socks proxy for Windows proxying through bastion
      shell: |
        ssh -i {{ ssh_key | default(infra_ssh_key) | default(ansible_ssh_private_key_file) | default(default_key_name)}} -o "ControlPath=~/.ssh/cp/ssh-%r@%h:%p" -O exit -p 22 {{hostvars[bastion_hostname].ansible_user}}@{{hostvars[bastion_hostname].public_ip_address}}
      when: win_connect_method | d('winrm') == 'psrp'