From 9bad84ea0b2a3ae125300c307d0751443bd7e43e Mon Sep 17 00:00:00 2001 From: Ajay Tripathi Date: Wed, 9 Dec 2020 01:39:00 +0530 Subject: [PATCH] [minor] ansible guidance linting --- README.md | 8 +++---- defaults/main.yml | 16 ++++++------- handlers/main.yml | 4 ++-- meta/main.yml | 3 ++- tasks/configure.yml | 6 ++--- tasks/install.deb.yml | 23 ++++++++++-------- tasks/opendkim.yml | 16 ++++++------- templates/main.cf.j2 | 38 +++++++++++++++--------------- templates/opendkim/KeyTable.j2 | 2 +- templates/opendkim/SigningTable.j2 | 2 +- templates/opendkim/TrustedHosts.j2 | 2 +- templates/sender_canonical_maps.j2 | 2 +- templates/virtual.j2 | 2 +- 13 files changed, 64 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index e353e30..4d5d4df 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,12 @@ Only tested on ubuntu for now. #### Variables ```yaml -postfix_enabled: yes # The role is enabled +postfix_enabled: true # The role is enabled -postfix_smtpd_use_tls: yes -postfix_myhostname: "{{inventory_hostname}}" +postfix_smtpd_use_tls: true +postfix_myhostname: "{{ inventory_hostname }}" postfix_myorigin: $myhostname -postfix_smtp_sasl_auth_enable: yes +postfix_smtp_sasl_auth_enable: true postfix_smtp_tls_cafile: "/etc/ssl/certs/Thawte_Premium_Server_CA.pem" postfix_relayhost: postfix_mynetworks: "127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128" diff --git a/defaults/main.yml b/defaults/main.yml index c8de45f..1472ca9 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,13 +1,13 @@ --- -postfix_enabled: yes # The role is enabled +postfix_enabled: true # The role is enabled -postfix_smtpd_use_tls: yes -postfix_myhostname: "{{inventory_hostname}}" +postfix_smtpd_use_tls: true +postfix_myhostname: "{{ inventory_hostname }}" postfix_myorigin: $myhostname -postfix_smtp_sasl_auth_enable: yes +postfix_smtp_sasl_auth_enable: true postfix_smtp_tls_CApath: "/etc/ssl/certs" -postfix_smtp_use_tls: yes +postfix_smtp_use_tls: true postfix_relayhost: postfix_mynetworks: "127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128" postfix_inet_interfaces: loopback-only @@ -20,9 +20,9 @@ postfix_os_service: "" postfix_generic_maps: "" # Install opendkim and setup postfix to use DKIM -postfix_dkim: no +postfix_dkim: false postfix_dkim_domains: - - "{{inventory_hostname}}" + - "{{ inventory_hostname }}" # Relay all mail going to local users (e.g. root or cron) to another mail address postfix_local_user_relay_address: "" @@ -44,7 +44,7 @@ maximal_backoff_time: 15m minimal_backoff_time: 5m queue_run_delay: 5m -postfix_tls_generate: False +postfix_tls_generate: false postfix_ssl_subject: "" postfix_tls_cert_file: "/etc/ssl/certs/ssl-cert-snakeoil.pem" postfix_tls_key_file: "/etc/ssl/private/ssl-cert-snakeoil.key" diff --git a/handlers/main.yml b/handlers/main.yml index d0952ed..2e5bd3c 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -9,5 +9,5 @@ notify: postfix send test mail - name: "postfix send test mail" - shell: echo "Test mail from new/updated postfix at" `hostname` | mail {{postfix_send_test_mail_to}} -s "Test SMTP `hostname`" - when: postfix_send_test_mail_to != "" + shell: echo "Test mail from new/updated postfix at" `hostname` | mail {{ postfix_send_test_mail_to }} -s "Test SMTP `hostname`" + when: postfix_send_test_mail_to | length > 0 diff --git a/meta/main.yml b/meta/main.yml index a1506be..ce88e40 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -7,6 +7,7 @@ galaxy_info: company: Stouts description: Manage postfix license: MIT + min_ansible_version: 2.8 platforms: - name: Ubuntu versions: @@ -17,6 +18,6 @@ galaxy_info: - name: CentOS versions: - all - categories: + galaxy_tags: - system - networking diff --git a/tasks/configure.yml b/tasks/configure.yml index d775f7f..ffc58c0 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -5,7 +5,7 @@ notify: postfix restart - name: Configure postfix pt. 1 - template: src={{item}}.j2 dest=/etc/postfix/{{item}} owner=root group=root mode=0644 + template: src={{ item }}.j2 dest=/etc/postfix/{{ item }} owner=root group=root mode=0644 notify: postfix restart with_items: - main.cf @@ -38,11 +38,11 @@ - name: Configure postfix local user relay template: src=virtual.j2 dest=/etc/postfix/virtual-pcre owner=root group=root mode=0644 notify: postfix restart - when: postfix_local_user_relay_address != "" + when: postfix_local_user_relay_address | length > 0 - name: Configure postfix sender canonical maps template: src=sender_canonical_maps.j2 dest=/etc/postfix/sender_canonical_maps - when: postfix_rewrite_sender_address != "" + when: postfix_rewrite_sender_address | length > 0 notify: postfix restart - name: Configure SystemD diff --git a/tasks/install.deb.yml b/tasks/install.deb.yml index 699a350..8d051c1 100644 --- a/tasks/install.deb.yml +++ b/tasks/install.deb.yml @@ -1,20 +1,23 @@ --- - name: Install requirements (Debian) - apt: name={{item}} update_cache=yes - with_items: - - postfix - - ca-certificates - - mailutils - - libsasl2-modules + apt: + update_cache: true + name: + - postfix + - ca-certificates + - mailutils + - libsasl2-modules + - name: Install DKIM requirements (Debian) apt: name={{item}} when: postfix_dkim with_items: - - opendkim - - opendkim-tools + - opendkim + - opendkim-tools - name: Install postfix-pcre - apt: pkg=postfix-pcre - when: postfix_rewrite_sender_address != "" or postfix_local_user_relay_address != "" + apt: + name: postfix-pcre + when: postfix_rewrite_sender_address | length > 0 or postfix_local_user_relay_address | length > 0 diff --git a/tasks/opendkim.yml b/tasks/opendkim.yml index b1d7fa7..65493f6 100644 --- a/tasks/opendkim.yml +++ b/tasks/opendkim.yml @@ -5,21 +5,21 @@ notify: postfix opendkim restart - name: Create DKIM directories - file: state=directory path=/etc/opendkim/keys/{{item}} recurse=true owner=root mode=0755 - with_items: "{{postfix_dkim_domains}}" + file: state=directory path=/etc/opendkim/keys/{{ item }} recurse=true owner=root mode=0755 + with_items: "{{ postfix_dkim_domains }}" notify: postfix opendkim restart - name: Generate DKIM key - command: opendkim-genkey -s mail -d "{{item}}" + command: opendkim-genkey -s mail -d "{{ item }}" args: - chdir: "/etc/opendkim/keys/{{item}}" - creates: "/etc/opendkim/keys/{{item}}/mail.private" - with_items: "{{postfix_dkim_domains}}" + chdir: "/etc/opendkim/keys/{{ item }}" + creates: "/etc/opendkim/keys/{{ item }}/mail.private" + with_items: "{{ postfix_dkim_domains }}" notify: postfix opendkim restart - name: Change DKIM key permissions - file: path=/etc/opendkim/keys/{{item}}/mail.private owner=opendkim group=opendkim mode=600 - with_items: "{{postfix_dkim_domains}}" + file: path=/etc/opendkim/keys/{{ item }}/mail.private owner=opendkim group=opendkim mode=600 + with_items: "{{ postfix_dkim_domains }}" - name: Configure opendkim pt. 1 template: src=opendkim/opendkim.conf.j2 dest=/etc/opendkim.conf owner=root group=root mode=0644 diff --git a/templates/main.cf.j2 b/templates/main.cf.j2 index 8d9059b..9405971 100644 --- a/templates/main.cf.j2 +++ b/templates/main.cf.j2 @@ -20,24 +20,24 @@ smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache {% if postfix_smtp_tls_wrappermode is defined %} -smtp_tls_wrappermode = {{postfix_smtp_tls_wrappermode}} +smtp_tls_wrappermode = {{ postfix_smtp_tls_wrappermode }} {% endif %} {% if postfix_smtp_tls_security_level is defined %} -smtp_tls_security_level = {{postfix_smtp_tls_security_level}} +smtp_tls_security_level = {{ postfix_smtp_tls_security_level }} {% endif %} {% endif %} -myhostname = {{postfix_myhostname}} -myorigin = {{postfix_myorigin}} +myhostname = {{ postfix_myhostname }} +myorigin = {{ postfix_myorigin }} alias_maps = hash:/etc/aliases smtp_generic_maps = hash:/etc/postfix/generic {% if postfix_rewrite_sender_address %} sender_canonical_maps = pcre:/etc/postfix/sender_canonical_maps {% endif %} alias_database = hash:/etc/aliases -mydestination = {{postfix_mydestination}} +mydestination = {{ postfix_mydestination }} {% if postfix_local_user_relay_address %} # Optional catch-all destination for unknown local(8) recipients: @@ -56,28 +56,28 @@ smtp_sasl_security_options = {{ postfix_smtp_sasl_security_options }} {% if postfix_smtp_use_tls %} smtp_use_tls = yes smtp_tls_security_level = encrypt -smtp_tls_CApath = {{postfix_smtp_tls_CApath}} +smtp_tls_CApath = {{ postfix_smtp_tls_CApath }} {% endif %} {% endif %} {% if postfix_relayhost %} -relayhost = {{postfix_relayhost}} +relayhost = {{ postfix_relayhost }} {% endif %} -mynetworks = {{postfix_mynetworks}} +mynetworks = {{ postfix_mynetworks }} mailbox_size_limit = 0 recipient_delimiter = + -inet_interfaces = {{postfix_inet_interfaces}} -inet_protocols = {{postfix_inet_protocols}} +inet_interfaces = {{ postfix_inet_interfaces }} +inet_protocols = {{ postfix_inet_protocols }} {% if postfix_smtpd_relay_restrictions|default(None) %} -smtpd_relay_restrictions = {{postfix_smtpd_relay_restrictions}} +smtpd_relay_restrictions = {{ postfix_smtpd_relay_restrictions }} {% endif %} {% if postfix_mydomain is defined %} -mydomain = {{postfix_mydomain}} +mydomain = {{ postfix_mydomain }} {% endif %} {% if postfix_notify_classes is defined %} -notify_classes = {{postfix_notify_classes}} +notify_classes = {{ postfix_notify_classes }} {% endif %} {% if postfix_use_procmail is defined %} @@ -85,7 +85,7 @@ mailbox_command = /usr/bin/procmail -a "$EXTENSION" {% endif %} {% if postfix_notify_classes is defined %} -notify_classes = {{postfix_notify_classes}} +notify_classes = {{ postfix_notify_classes }} {% endif %} {% if postfix_dkim %} @@ -96,8 +96,8 @@ non_smtpd_milters = inet:localhost:12301 {% endif %} # Queue -bounce_queue_lifetime = {{bounce_queue_lifetime}} -maximal_queue_lifetime = {{maximal_queue_lifetime}} -maximal_backoff_time = {{maximal_backoff_time}} -minimal_backoff_time = {{minimal_backoff_time}} -queue_run_delay = {{queue_run_delay}} +bounce_queue_lifetime = {{ bounce_queue_lifetime }} +maximal_queue_lifetime = {{ maximal_queue_lifetime }} +maximal_backoff_time = {{ maximal_backoff_time }} +minimal_backoff_time = {{ minimal_backoff_time }} +queue_run_delay = {{ queue_run_delay }} diff --git a/templates/opendkim/KeyTable.j2 b/templates/opendkim/KeyTable.j2 index 7336c5b..2c1c95e 100644 --- a/templates/opendkim/KeyTable.j2 +++ b/templates/opendkim/KeyTable.j2 @@ -1,3 +1,3 @@ {%for item in postfix_dkim_domains -%} -mail._domainkey.{{item}} {{item}}:mail:/etc/opendkim/keys/{{item}}/mail.private +mail._domainkey.{{ item }} {{ item }}:mail:/etc/opendkim/keys/{{ item }}/mail.private {%endfor %} diff --git a/templates/opendkim/SigningTable.j2 b/templates/opendkim/SigningTable.j2 index 97aaf1a..00c1afb 100644 --- a/templates/opendkim/SigningTable.j2 +++ b/templates/opendkim/SigningTable.j2 @@ -1,3 +1,3 @@ {% for item in postfix_dkim_domains -%} -*@{{item}} mail._domainkey.{{item}} +*@{{ item }} mail._domainkey.{{ item }} {% endfor %} diff --git a/templates/opendkim/TrustedHosts.j2 b/templates/opendkim/TrustedHosts.j2 index 35de6d7..6863836 100644 --- a/templates/opendkim/TrustedHosts.j2 +++ b/templates/opendkim/TrustedHosts.j2 @@ -3,5 +3,5 @@ localhost 192.168.0.1/24 {%for item in postfix_dkim_domains -%} -*.{{item}} +*.{{ item }} {%endfor %} diff --git a/templates/sender_canonical_maps.j2 b/templates/sender_canonical_maps.j2 index e2c4eb6..678040d 100644 --- a/templates/sender_canonical_maps.j2 +++ b/templates/sender_canonical_maps.j2 @@ -1,3 +1,3 @@ {% if postfix_rewrite_sender_address %} -/.+/ {{postfix_rewrite_sender_address}} +/.+/ {{ postfix_rewrite_sender_address }} {% endif %} diff --git a/templates/virtual.j2 b/templates/virtual.j2 index 83fac89..3a76f63 100644 --- a/templates/virtual.j2 +++ b/templates/virtual.j2 @@ -1 +1 @@ -/.+@localhost/ {{postfix_local_user_relay_address}} +/.+@localhost/ {{ postfix_local_user_relay_address }}