25-10-24
ansible 配置dns、mail服务
1-ansible
---- name: Basic Configuration hosts: all gather_facts: false tasks: - name: Install basic packet raw: apt install -y dbus vim python3 register: reg1 changed_when: "'will be installed' in reg1.stdout" - name: start dbus service systemd: name: dbus state: started - name: Set hostname hostname: name: "{{ inventory_hostname }}" register: reg2 - name: x11 key map raw: localectl set-x11-keymap us when: reg2.changed - name: FQDN lineinfile: path: /etc/hosts search_string: "127.0.1.1" line: "127.0.1.1 {{ inventory_hostname }}.shanghai.org {{ inventory_hostname }} debian" - name: Install ntp client apt: name: ntp update_cache: false - name: Configure ntp client copy: src: /data/ntp.conf dest: /etc/ntpsec/ntp.conf register: ntp - name: Restart ntp client systemd: name: ntp state: restarted when: ntp.changed- name: Configure DNS service hosts: all gather_facts: false tasks: - name: Install dns service apt: name: - bind9 - dnsutils update_cache: false - name: Create resolv.conf file file: path: /etc/resolv.conf state: touch modification_time: preserve access_time: preserve - name: Set dns server address lineinfile: path: /etc/resolv.conf line: "nameserver {{ ansible_host }}" - name: Configure dns service copy: src: "/data/{{ item }}" dest: /etc/bind loop: - named.conf - db.shanghai.org register: dns - name: restart dns service systemd: name: bind9 state: restarted when: dns.changed- name: Configure Mail Service hosts: all gather_facts: false tasks: - name: Install mail service apt: name: - postfix - dovecot-imapd - ca-certificates update_cache: false - name: copy ssl certificate copy: src: "/data/{{ item }}" dest: /etc/ssl loop: - ssl.crt - ssl.key - name: copy ssl certificate copy: src: /data/ca.crt dest: /usr/local/share/ca-certificates register: ssl - name: trust the root ca raw: /usr/sbin/update-ca-certificates when: ssl.changed - name: Configure postfix service copy: src: "/data/{{ item }}" dest: /etc/postfix loop: - main.cf - master.cf register: postfix - name: Restart postfix service systemd: name: postfix state: restarted when: postfix.changed - name: Configure dovecot service copy: src: "/data/{{ item }}" dest: /etc/dovecot/conf.d loop: - 10-auth.conf - 10-ssl.conf - 10-master.conf register: dovecot - name: Restart dovecot service systemd: name: dovecot state: restarted when: dovecot.changed - name: Create Mail user user: name: zhangsan password: "{{ 'Skills39' | password_hash('sha512') }}" shell: /bin/bash update_password: on_create state: present - name: Create Mail user user: name: lisi password: "{{ 'Skills39' | password_hash('sha512') }}" shell: /bin/bash update_password: on_create state: present