-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f73cb8
commit e8ad89b
Showing
10 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
--- | ||
# File: install_linux_repo.yml - package installation tasks for Consul | ||
|
||
- name: Install OS packages | ||
package: | ||
name: "{{ item }}" | ||
state: present | ||
with_items: "{{ consul_os_packages }}" | ||
tags: installation | ||
|
||
- name: Populate service facts | ||
service_facts: | ||
|
||
- name: Gather the package facts | ||
package_facts: | ||
manager: auto | ||
|
||
- name: Clean up previous consul data | ||
block: | ||
- name: Stop service consul, if running | ||
systemd: | ||
name: consul | ||
state: stopped | ||
when: ansible_facts.services['consul.service'] is defined | ||
|
||
- name: Remove consul systemd unit file from previous installation | ||
file: | ||
path: /usr/lib/systemd/system/consul.service | ||
state: absent | ||
notify: systemctl daemon-reload | ||
|
||
- name: Remove the user 'consul' | ||
user: | ||
name: consul | ||
state: absent | ||
remove: yes | ||
|
||
when: | ||
- "ansible_distribution|lower == 'redhat' or ansible_distribution|lower == 'centos' or \ | ||
ansible_distribution|lower == 'fedora' or ansible_distribution|lower == 'amazon' or \ | ||
ansible_distribution|lower == 'debian' or ansible_distribution|lower == 'ubuntu'" | ||
- "'consul' not in ansible_facts.packages" | ||
|
||
- name: Install repository | ||
block: | ||
- name: Add Redhat/CentOS/Fedora/Amazon Linux repository | ||
command: "yum-config-manager --add-repo {{ consul_repo_url }}" | ||
args: | ||
creates: /etc/yum.repos.d/hashicorp.repo | ||
when: "ansible_distribution|lower == 'redhat' or ansible_distribution|lower == 'centos' or \ | ||
ansible_distribution|lower == 'fedora' or ansible_distribution|lower == 'amazon'" | ||
|
||
|
||
- name: Add an Apt signing key, uses whichever key is at the URL | ||
apt_key: | ||
url: https://apt.releases.hashicorp.com/gpg | ||
state: present | ||
when: ansible_distribution|lower == 'debian' or ansible_distribution|lower == 'ubuntu' | ||
|
||
- name: Add Debian/Ubuntu Linux repository | ||
apt_repository: | ||
repo: "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | ||
state: present | ||
update_cache: true | ||
when: ansible_distribution|lower == 'debian' or ansible_distribution|lower == 'ubuntu' | ||
|
||
- name: Install consul package | ||
package: | ||
name: "consul-{{ consul_version }}" | ||
state: present | ||
|
||
- name: Create a directory /etc/systemd/system/consul.service.d | ||
file: | ||
path: /etc/systemd/system/consul.service.d | ||
state: directory | ||
mode: '0755' | ||
owner: root | ||
group: root | ||
register: systemd_override | ||
|
||
|
||
- name: Override systemd service params | ||
template: | ||
src: consul_systemd_service.override.j2 | ||
dest: /etc/systemd/system/consul.service.d/override.conf | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
register: systemd_override | ||
notify: | ||
- systemctl daemon-reload | ||
- restart consul | ||
when: | ||
- ansible_service_mgr == "systemd" | ||
- not ansible_os_family == "FreeBSD" | ||
- not ansible_os_family == "Solaris" | ||
- consul_install_from_repo | bool | ||
|
||
- name: Flush handlers | ||
meta: flush_handlers | ||
|
||
- name: As, this role work with json conf file only - delete file /etc/consul.d/consul.hcl | ||
file: | ||
path: /etc/consul.d/consul.hcl | ||
state: absent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# WARNING!!! Ansible managed. | ||
|
||
[Unit] | ||
ConditionFileNotEmpty= | ||
ConditionFileNotEmpty={{ consul_config_path }}/config.json | ||
|
||
[Service] | ||
ExecStart= | ||
ExecStart=/usr/bin/consul agent -config-file={{ consul_config_path }}/config.json -config-dir={{ consul_configd_path }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
|
||
consul_os_packages: | ||
- unzip | ||
|
||
consul_os_prepare_packages: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters