forked from CCCHH/ansible-infra
		
	msmtp(role): introduce msmtp role
Introduce msmtp role for setting up msmtp for mail sending. Also add accompanying host group and playbook play.
This commit is contained in:
		
					parent
					
						
							
								18dda95c46
							
						
					
				
			
			
				commit
				
					
						afceb886dc
					
				
			
		
					 6 changed files with 83 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -186,3 +186,5 @@ alloy_hosts:
 | 
			
		|||
ansible_pull_hosts:
 | 
			
		||||
  hosts:
 | 
			
		||||
    netbox:
 | 
			
		||||
msmtp_hosts:
 | 
			
		||||
  hosts:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -83,5 +83,10 @@
 | 
			
		|||
  roles:
 | 
			
		||||
    - ansible_pull
 | 
			
		||||
 | 
			
		||||
- name: Ensure msmtp is setup on msmtp_hosts
 | 
			
		||||
  hosts: msmtp_hosts
 | 
			
		||||
  roles:
 | 
			
		||||
    - msmtp
 | 
			
		||||
 | 
			
		||||
- name: Run ensure_eh22_styleguide_dir Playbook
 | 
			
		||||
  ansible.builtin.import_playbook: ensure_eh22_styleguide_dir.yaml
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										21
									
								
								roles/msmtp/README.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								roles/msmtp/README.md
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,21 @@
 | 
			
		|||
# Role `msmtp`
 | 
			
		||||
 | 
			
		||||
A role for setting up msmtp for mail sending.
 | 
			
		||||
 | 
			
		||||
The role only supports mail servers supporting either STARTTLS or SMTPS.
 | 
			
		||||
 | 
			
		||||
## Supported Distributions
 | 
			
		||||
 | 
			
		||||
Should work on Debian-based distributions.
 | 
			
		||||
 | 
			
		||||
## Required Arguments
 | 
			
		||||
 | 
			
		||||
- `msmtp__smtp_host`: The SMTP host to use.
 | 
			
		||||
- `msmtp__smtp_port`: The SMTP port to use.
 | 
			
		||||
- `msmtp__smtp_tls_method`: The SMTP TLS method to use.  
 | 
			
		||||
  Possible choices:
 | 
			
		||||
  - `starttls`: Use STARTTLS to connect to the server.
 | 
			
		||||
  - `smtps`: Use SMTPS to connect to the server.
 | 
			
		||||
- `msmtp__smtp_user`: The SMTP user to use for authentication.
 | 
			
		||||
- `msmtp__smtp_password`: The SMTP password to use for authentication.
 | 
			
		||||
- `msmtp__smtp_from`: The SMTP from address to use when sending mails.
 | 
			
		||||
							
								
								
									
										24
									
								
								roles/msmtp/meta/argument_specs.yaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								roles/msmtp/meta/argument_specs.yaml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
argument_specs:
 | 
			
		||||
  main:
 | 
			
		||||
    options:
 | 
			
		||||
      msmtp__smtp_host:
 | 
			
		||||
        type: str
 | 
			
		||||
        required: true
 | 
			
		||||
      msmtp__smtp_port:
 | 
			
		||||
        type: int
 | 
			
		||||
        required: true
 | 
			
		||||
      msmtp__smtp_tls_method:
 | 
			
		||||
        type: str
 | 
			
		||||
        required: true
 | 
			
		||||
        choices:
 | 
			
		||||
          - "starttls"
 | 
			
		||||
          - "smtps"
 | 
			
		||||
      msmtp__smtp_user:
 | 
			
		||||
        type: str
 | 
			
		||||
        required: true
 | 
			
		||||
      msmtp__smtp_password:
 | 
			
		||||
        type: str
 | 
			
		||||
        required: true
 | 
			
		||||
      msmtp__smtp_from:
 | 
			
		||||
        type: str
 | 
			
		||||
        required: true
 | 
			
		||||
							
								
								
									
										14
									
								
								roles/msmtp/tasks/main.yaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								roles/msmtp/tasks/main.yaml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,14 @@
 | 
			
		|||
- name: ensure msmtp is installed
 | 
			
		||||
  ansible.builtin.apt:
 | 
			
		||||
    name: msmtp
 | 
			
		||||
    state: present
 | 
			
		||||
  become: true
 | 
			
		||||
 | 
			
		||||
- name: ensure msmtp config for root user
 | 
			
		||||
  ansible.builtin.template:
 | 
			
		||||
    src: msmtprc.j2
 | 
			
		||||
    dest: /root/.msmtprc
 | 
			
		||||
    owner: root
 | 
			
		||||
    group: root
 | 
			
		||||
    mode: "0600"
 | 
			
		||||
  become: true
 | 
			
		||||
							
								
								
									
										17
									
								
								roles/msmtp/templates/msmtprc.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								roles/msmtp/templates/msmtprc.j2
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
# ansible-managed
 | 
			
		||||
 | 
			
		||||
# defaults
 | 
			
		||||
defaults
 | 
			
		||||
auth on
 | 
			
		||||
tls on
 | 
			
		||||
 | 
			
		||||
# ansible-managed-account
 | 
			
		||||
account ansible-managed-account
 | 
			
		||||
host {{ msmtp__smtp_host }}
 | 
			
		||||
port {{ msmtp__smtp_port }}
 | 
			
		||||
tls_starttls {% if msmtp__smtp_tls_method == "starttls" %}on{% else %}off{% endif +%}
 | 
			
		||||
user {{ msmtp__smtp_user }}
 | 
			
		||||
password {{ msmtp__smtp_password }}
 | 
			
		||||
from {{ msmtp__smtp_from }}
 | 
			
		||||
 | 
			
		||||
account default: ansible-managed-account
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue