aboutsummaryrefslogtreecommitdiffhomepage
path: root/Vagrant/bootstrap.yml
blob: fbd17cb1165667af0975234565f31d536e550e25 (plain) (blame)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
---
- hosts: all
  remote_user: vagrant
  become: true
  vars:
    - host_vars_directory: './host_vars'
    - host_vars_file: '{{ host_vars_directory }}/{{ inventory_hostname }}.yml'
    - pri_domain_name: 'vagrant.local'
    - ssh_key_path: '.vagrant/machines/{{ inventory_hostname }}/virtualbox/private_key'
    - update_host_vars: true
  roles:
  tasks:
    - name: updating apt cache (Debian)
      apt:
        update_cache: yes
        cache_valid_time: 3600
      when: ansible_os_family == "Debian"

    - name: installing ansible pre-reqs (Debian)
      apt:
        name: "{{ item }}"
        state: present
      with_items:
        - libffi-dev
        - libssl-dev
        - python-dev
        - python-setuptools
      when: >
            ansible_os_family == "Debian"

    - name: installing epel repo (RedHat)
      yum:
        name: "epel-release"
        state: present
      when: >
            ansible_os_family == "RedHat" and
            ansible_distribution != "Fedora"

    - name: installing ansible pre-reqs (RedHat)
      yum:
        name: "{{ item }}"
        state: present
      with_items:
        - libffi-devel
        - openssl-devel
        - python-crypto
        - python-devel
        - python-setuptools
      when: >
            ansible_os_family == "RedHat" and
            ansible_distribution != "Fedora"

    - name: installing ansible pre-reqs (Fedora)
      dnf:
        name: "{{ item }}"
        state: present
      with_items:
        - gmp-devel
        - libffi-devel
        - openssl-devel
        - python-crypto
        - python-devel
        - python-dnf
        - python-setuptools
        - redhat-rpm-config
      when: >
            ansible_os_family == "RedHat" and
            ansible_distribution == "Fedora"

    - name: installing ansible pre-reqs (openSUSE)
      zypper:
        name: "{{ item }}"
        state: present
      with_items:
        - gmp-devel
        - libffi-devel
        - openssl-devel
        - python-crypto
        - python-devel
        - python-setuptools
      when: >
            ansible_os_family == "openSUSE Leap"

    - name: installing python pip
      easy_install:
        name: "pip"
        state: present

    - name: installing ansible
      pip:
        name: "ansible"
        state: present
        version: 1.9.6

    - name: ensuring host_vars directory exists
      file:
        path: "./host_vars"
        state: directory
      delegate_to: localhost
      run_once: true
      become: false
      when: update_host_vars is defined and update_host_vars

    - name: ensuring host file exists in host_vars
      stat:
        path: "{{ host_vars_file }}"
      delegate_to: localhost
      register: host_var
      become: false
      when: >
            update_host_vars is defined and
            update_host_vars

    - name: creating missing host_vars
      file:
        path: "{{ host_vars_file }}"
        state: touch
      delegate_to: localhost
      become: false
      when: not host_var.stat.exists

    - name: updating ansible_ssh_port
      lineinfile:
        dest: "{{ host_vars_file }}"
        regexp: "^ansible_ssh_port{{ ':' }}"
        line: "ansible_ssh_port{{ ':' }} 22"
      delegate_to: localhost
      become: false
      when: >
            (update_host_vars is defined and
            update_host_vars) and
            (ansible_eth1 is defined or
            ansible_enp0s8 is defined)

    - name: updating ansible_ssh_host
      lineinfile:
        dest: "{{ host_vars_file }}"
        regexp: "^ansible_ssh_host{{ ':' }}"
        line: "ansible_ssh_host{{ ':' }} {{ ansible_eth1.ipv4.address }}"
      delegate_to: localhost
      become: false
      when: >
            (update_host_vars is defined and
            update_host_vars) and
            ansible_eth1 is defined

    - name: updating ansible_ssh_host
      lineinfile:
        dest: "{{ host_vars_file }}"
        regexp: "^ansible_ssh_host{{ ':' }}"
        line: "ansible_ssh_host{{ ':' }} {{ ansible_enp0s8.ipv4.address }}"
      delegate_to: localhost
      become: false
      when: >
            (update_host_vars is defined and
            update_host_vars) and
            ansible_enp0s8 is defined

    - name: updating ansible_ssh_key
      lineinfile:
        dest: "{{ host_vars_file }}"
        regexp: "^ansible_ssh_private_key_file{{ ':' }}"
        line: "ansible_ssh_private_key_file{{ ':' }} {{ ssh_key_path }}"
      delegate_to: localhost
      become: false
      when: >
            update_host_vars is defined and
            update_host_vars

    - name: ensuring host_vars is yaml formatted
      lineinfile:
        dest: "{{ host_vars_file }}"
        regexp: "---"
        line: "---"
        insertbefore: BOF
      delegate_to: localhost
      become: false
      when: >
            update_host_vars is defined and
            update_host_vars