Initial commit
[ta/infra-ansible.git] / roles / bootstrap-host / tasks / install_packages.yml
1 ---
2 # Copyright 2015, Rackspace US, Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # Ubuntu
17 - block:
18   - name: Ensure that apt supports HTTPS package sources
19     apt:
20       name: apt-transport-https
21       state: present
22     tags:
23       - apt-install-prerequisites
24
25   - name: Determine the existing Ubuntu repo configuration
26     command: 'grep -oP "^deb \K(\[?.*\]?.*ubuntu\S*\/?)(?= {{ ansible_distribution_release }} main)" /etc/apt/sources.list'
27     register: ubuntu_repo
28     when:
29       - bootstrap_host_ubuntu_repo is not defined
30     changed_when: false
31     tags:
32       - find-apt-repo
33
34   - name: Determine the existing Ubuntu Security repo configuration
35     command: 'grep -oP "^deb \K(\[?.*\]?.*ubuntu\S*\/?)(?= {{ ansible_distribution_release }}-security main)" /etc/apt/sources.list'
36     register: ubuntu_security_repo
37     when:
38       - bootstrap_host_ubuntu_security_repo is not defined
39     changed_when: false
40     tags:
41       - find-apt-security-repo
42
43   - name: Set apt repo facts based on discovered information
44     set_fact:
45       bootstrap_host_ubuntu_repo: "{{ ubuntu_repo.stdout_lines[0] }}"
46       bootstrap_host_ubuntu_security_repo: "{{ ubuntu_security_repo.stdout_lines[0] }}"
47     when:
48       - bootstrap_host_ubuntu_repo is not defined
49       - bootstrap_host_ubuntu_security_repo is not defined
50       - ubuntu_repo is defined
51       - ubuntu_security_repo is defined
52
53   - name: Configure apt's sources.list (Ubuntu only)
54     template:
55       src: apt-sources.list.j2
56       dest: /etc/apt/sources.list
57       backup: yes
58     when:
59       - ansible_distribution == 'Ubuntu'
60       - bootstrap_host_ubuntu_repo is defined
61       - bootstrap_host_ubuntu_security_repo is defined
62     register: apt_sources_configure
63
64   - name: Update apt-cache
65     apt:
66       update_cache: yes
67     when:
68       - apt_sources_configure is defined
69       - apt_sources_configure | changed
70     tags:
71       - apt-cache-update
72
73   when:
74     - ansible_pkg_mgr == 'apt'
75
76 # CentOS
77 - block:
78   - name: Install RDO package
79     package:
80       name: "{{ rdo_package }}"
81       state: "present"
82     register: install_cloud_rdo_package
83     until: install_cloud_rdo_package | success
84     retries: 5
85     delay: 2
86
87   - name: Install epel package
88     package:
89       name: "{{ epel_package }}"
90       state: "present"
91     register: install_epel_package
92     until: install_epel_package | success
93     retries: 5
94     delay: 2
95
96   when:
97     - ansible_pkg_mgr == 'yum'
98
99 - name: Remove known problem packages
100   package:
101     name: "{{ item }}"
102     state: absent
103   with_items: "{{ packages_remove }}"
104   tags:
105     - remove-packages
106
107 - name: Install packages
108   package:
109     name: "{{ item }}"
110     state: present
111   with_items: "{{ packages_install }}"
112   tags:
113     - install-packages
114