adds consul configuration role
This commit is contained in:
		
							parent
							
								
									2185a79d8f
								
							
						
					
					
						commit
						c5281bd0fb
					
				
					 2 changed files with 71 additions and 0 deletions
				
			
		
							
								
								
									
										28
									
								
								ansible/roles/configure-consul/tasks/configure.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								ansible/roles/configure-consul/tasks/configure.yml
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,28 @@
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Copy consul base configuration
 | 
				
			||||||
 | 
					  become: true
 | 
				
			||||||
 | 
					  template:
 | 
				
			||||||
 | 
					    src: consul.hcl.j2
 | 
				
			||||||
 | 
					    dest: /etc/consul.d/consul.hcl
 | 
				
			||||||
 | 
					    owner: consul
 | 
				
			||||||
 | 
					    group: consul
 | 
				
			||||||
 | 
					    mode: 0640
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Copy consul-server configuration
 | 
				
			||||||
 | 
					  become: true
 | 
				
			||||||
 | 
					  template:
 | 
				
			||||||
 | 
					    src: consul-server.hcl.j2
 | 
				
			||||||
 | 
					    dest: /etc/consul.d/consul-server.hcl
 | 
				
			||||||
 | 
					    owner: consul
 | 
				
			||||||
 | 
					    group: consul
 | 
				
			||||||
 | 
					    mode: 0640
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Copy consul systemd unit file
 | 
				
			||||||
 | 
					  become: true
 | 
				
			||||||
 | 
					  template:
 | 
				
			||||||
 | 
					    src: consul.service
 | 
				
			||||||
 | 
					    dest: /etc/systemd/system/consul.service
 | 
				
			||||||
 | 
					    owner: root
 | 
				
			||||||
 | 
					    group: root
 | 
				
			||||||
 | 
					    mode: 0644
 | 
				
			||||||
							
								
								
									
										43
									
								
								ansible/roles/configure-consul/tasks/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								ansible/roles/configure-consul/tasks/main.yml
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,43 @@
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					- name: Install or update consul
 | 
				
			||||||
 | 
					  become: true
 | 
				
			||||||
 | 
					  apt:
 | 
				
			||||||
 | 
					    name: consul
 | 
				
			||||||
 | 
					    state: latest
 | 
				
			||||||
 | 
					    update_cache: yes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Add consul user
 | 
				
			||||||
 | 
					  become: true
 | 
				
			||||||
 | 
					  user:
 | 
				
			||||||
 | 
					    name: consul
 | 
				
			||||||
 | 
					    system: yes
 | 
				
			||||||
 | 
					    shell: /bin/false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Create consul directories
 | 
				
			||||||
 | 
					  become: true
 | 
				
			||||||
 | 
					  file:
 | 
				
			||||||
 | 
					    path: "{{ item }}"
 | 
				
			||||||
 | 
					    state: directory
 | 
				
			||||||
 | 
					    owner: consul
 | 
				
			||||||
 | 
					    group: consul
 | 
				
			||||||
 | 
					  with_items:
 | 
				
			||||||
 | 
					    - /etc/consul.d
 | 
				
			||||||
 | 
					    - /opt/consul
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- include_tasks: configure.yml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Enable and start consul
 | 
				
			||||||
 | 
					  become: true
 | 
				
			||||||
 | 
					  systemd:
 | 
				
			||||||
 | 
					    name: consul
 | 
				
			||||||
 | 
					    enabled: yes
 | 
				
			||||||
 | 
					    state: started
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Check if consul is running
 | 
				
			||||||
 | 
					  become: true
 | 
				
			||||||
 | 
					  shell: consul members
 | 
				
			||||||
 | 
					  register: consul_members
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Print consul members
 | 
				
			||||||
 | 
					  debug:
 | 
				
			||||||
 | 
					    msg: "{{ consul_members.stdout_lines }}"
 | 
				
			||||||
		Loading…
	
		Reference in a new issue