Initial commit

This commit is contained in:
2022-06-26 19:46:33 +02:00
commit 818d34657c
106 changed files with 1390 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
env/*
+38
View File
@@ -0,0 +1,38 @@
# Ansible från grunden
Här finner du all exempelkod för boken *Ansible från grunden*
(ISBN: 978-91-983300-9-0).
Boken kommer att ges ut under sensommaren/hösten 2022.
Boken kommer att finnas till försäljning hos [CyberInfo Sverige](https://www.cyberinfo.se/bocker/),
[Bokus](https://www.bokus.com/cgi-bin/product_search.cgi?publisher=CyberInfo%20Sverige) och
[Adlibris](https://www.adlibris.com/se/sok?filter=publisher%3ACyberInfo%20Sverige).
## Baksidetexten
**Ansible från grunden** lär ut det vi behöver för att komma igång med
Ansible. Boken börjar med en genomgång av vad Ansible är, hur det används och
vad det används till. Vi tittar också på hur man installerar Ansible i en
virtuell Pythonmiljö.
Därefter lär vi oss hur man kör ad hoc-kommandon för att snabbt
fixa något; hur man skriver egna playbooks för att utföra en lång rad
uppgifter; hur man skriver roller för att på ett enkelt sätt återanvända
Ansible-kod. Vi lär oss också hur man krypterar filer som innehåller lösenord
eller andra känsliga uppgifter.
Boken är uppbyggd av både enklare, mindre exempel, men också av ett par stora
projekt som vi gång på gång modifierar och förbättrar. I boken finns cirka ett
hundra exempel. Efter varje kapitel finns övningsuppgifter av varierande
svårighetsgrad.
Bokens huvudfokus är att managera Linuxsystem. Men det finns även ett kort
kapitel som visar hur man kan använda Ansible för att managera Windows.
För att få ut det mesta av boken bör man vara bekväm med att arbeta med
Linux och kommandon. Man bör också vara van vid att arbeta med SSH. En
generell kännedom om Apache och Postfix underlättar också, även om det inte är
något krav.
## Framsidan
![Ansible från grunden](framsidan-ansible-fran-grunden.jpg)
+21
View File
@@ -0,0 +1,21 @@
- hosts: ankeborg
become: true
vars:
timezone: Europe/Stockholm
collections:
- jackbenny.demo
tasks:
- name: Test my dummy module
dummy:
number: 51
register: the_num
- name: Print the return value
debug:
msg: "{{ the_num }}"
roles:
- base
+18
View File
@@ -0,0 +1,18 @@
- hosts: ankeborg
become: true
vars:
timezone: Europe/Stockholm
tasks:
- name: Test my dummy module
jackbenny.demo.dummy:
number: 51
register: the_num
- name: Print the return value
debug:
msg: "{{ the_num }}"
roles:
- jackbenny.demo.base
+13
View File
@@ -0,0 +1,13 @@
- hosts: ankeborg
become: true
vars:
mail_hostname: "{{ inventory_hostname }}"
canonical_name: "{{ inventory_hostname_short }}.mynet.\
example.com"
relay_user: xxx
relay_password: yyy
external_email_address: me@example.com
roles:
- jackbenny.postfix
+21
View File
@@ -0,0 +1,21 @@
- hosts: ankeborg
become: true
vars:
mail_hostname: "{{ inventory_hostname }}"
canonical_name: "{{ inventory_hostname_short }}.nixnet.\
example.tld"
pre_tasks:
- name: Update cache on Debian/Ubuntu
apt:
update_cache: yes
when: ansible_os_family == 'Debian'
- name: Update cache on RedHat/CentOS/Fedora
dnf:
update_cache: yes
when: ansible_os_family == 'RedHat'
roles:
- base
- postfix-v2
+11
View File
@@ -0,0 +1,11 @@
- hosts: ankeborg
become: true
vars:
mail_hostname: "{{ inventory_hostname }}"
canonical_name: "{{ inventory_hostname_short }}.nixnet.\
example.tld"
roles:
- base-v2
- postfix-v3
+11
View File
@@ -0,0 +1,11 @@
- hosts: ankeborg
become: true
vars:
mail_hostname: "{{ inventory_hostname }}"
canonical_name: "{{ inventory_hostname_short }}.nixnet.\
example.tld"
roles:
- base-v2
- postfix-v4
+21
View File
@@ -0,0 +1,21 @@
- hosts: ankeborg
become: true
vars:
mail_hostname: "{{ inventory_hostname }}"
canonical_name: "{{ inventory_hostname_short }}.nixnet.\
example.tld"
pre_tasks:
- name: Update cache on Debian/Ubuntu
apt:
update_cache: yes
when: ansible_os_family == 'Debian'
- name: Update cache on RedHat/CentOS/Fedora
dnf:
update_cache: yes
when: ansible_os_family == 'RedHat'
roles:
- base
- postfix
+16
View File
@@ -0,0 +1,16 @@
- hosts: ankeborg
become: true
pre_tasks:
- name: Update cache on Debian/Ubuntu
apt:
update_cache: yes
when: ansible_os_family == 'Debian'
- name: Update cache on RedHat/CentOS/Fedora
dnf:
update_cache: yes
when: ansible_os_family == 'RedHat'
roles:
- base
+2
View File
@@ -0,0 +1,2 @@
[defaults]
inventory = $HOME/ansible/hosts
+6
View File
@@ -0,0 +1,6 @@
import crypt, getpass
password = (crypt.crypt(getpass.getpass(),
crypt.mksalt(crypt.METHOD_SHA512)))
f = open("newuser.pass", "w")
f.write(password)
f.close()
+12
View File
@@ -0,0 +1,12 @@
- name: Min första Play
hosts: ankeborg
become: true
tasks:
- name: Skapa användaren Kalle
user:
name: kalle
password: "$6$WAFtsM1BDHKlAGcF$jyMA41xQONrF0y\
/EuydPutK.CfVCJzfIzdb8qnw.Q75oOMUMrUoNSXJ2r\
tzwvTjX2xAmz0FxUy51vS2tc8zVs/"
shell: /bin/bash
create_home: yes
+13
View File
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bara ett test</title>
</head>
<body>
<?php echo "<h1>Hejsan!</h1>" ?>
</body>
</html>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

+11
View File
@@ -0,0 +1,11 @@
- hosts: all
strategy: free
tasks:
- name: Run whoami
command:
cmd: whoami
- name: Run uptime
command:
cmd: uptime
+3
View File
@@ -0,0 +1,3 @@
ansible_user: jake
ansible_become_pass: peak-airspeed
ansible_become_method: sudo
+18
View File
@@ -0,0 +1,18 @@
- name: Playbook för att demonstrera hanterare
hosts: tjatte.nixnet.jke
become: yes
tasks:
- name: Installera MariaDB
dnf:
name: mariadb-server
state: present
update_cache: yes
notify: Aktivera MariaDB
handlers:
- name: Aktivera MariaDB
systemd:
name: mariadb
state: started
enabled: yes
+2
View File
@@ -0,0 +1,2 @@
ansible_become_method: su
ansible_become_pass: speech-fargo
+2
View File
@@ -0,0 +1,2 @@
ansible_become_method: su
ansible_become_pass: speech-fargo
+8
View File
@@ -0,0 +1,8 @@
ansible_user: Jack-Benny
ansible_password: blue-panter
ansible_connection: winrm
ansible_winrm_transport: basic
ansible_winrm_server_cert_validation: ignore
ansible_winrm_scheme: https
ansible_port: 5986
+8
View File
@@ -0,0 +1,8 @@
[ankeborg]
knatte.nixnet.jke ansible_host=192.168.0.29
fnatte.nixnet.jke ansible_host=192.168.0.24
tjatte.nixnet.jke ansible_host=192.168.0.42
joakim.nixnet.jke ansible_host=192.168.0.47
[win10]
win10-lab ansible_host=192.168.0.40
+13
View File
@@ -0,0 +1,13 @@
- name: Testa import_tasks och include_tasks
hosts: localhost
tasks:
- include_tasks: x.yml # import_tasks fungerar
with_items: [1, 2, 3] # inte för loopar
- name: Läsa taggar fungerar bara med import
hosts: localhost
vars:
- testar: hejsan
tasks:
- import_tasks: y.yml
+13
View File
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bara ett test</title>
</head>
<body>
<?php echo "<h1>Hejsan!</h1>" ?>
</body>
</html>
+8
View File
@@ -0,0 +1,8 @@
- hosts: all
become: yes
tasks:
- name: Install vim
package:
name: vim
state: present
+7
View File
@@ -0,0 +1,7 @@
- hosts: localhost
tasks:
- name: Lista hela hostvars
debug:
msg: "{{ hostvars }}"
+14
View File
@@ -0,0 +1,14 @@
- hosts: localhost
vars:
namn:
- Knatte
- Tjatte
- Fnatte
- Joakim
tasks:
- name: If-test
template:
src: testfil_if.j2
dest: testfil_if.txt
+9
View File
@@ -0,0 +1,9 @@
- name: Extract test
hosts: localhost
tasks:
- name: Lista IP
debug:
msg: "{{ groups['ankeborg'] | map('extract',
hostvars, ['ansible_host']) }}"
+9
View File
@@ -0,0 +1,9 @@
- name: Extract test
hosts: localhost
tasks:
- name: Lista IP
debug:
msg: "{{ ['knatte.nixnet.jke'] | map('extract',
hostvars, ['ansible_host']) }}"
+14
View File
@@ -0,0 +1,14 @@
- hosts: localhost
vars:
namn:
- Knatte
- Tjatte
- Fnatte
- Joakim
tasks:
- name: Loop-test
template:
src: testfil_loop.j2
dest: testfil_loop.txt
+9
View File
@@ -0,0 +1,9 @@
- name: Extract test
hosts: localhost
tasks:
- name: Lista alla lösenord
debug:
msg: "{{ groups['ankeborg'] | map('extract',
hostvars, ['ansible_become_pass']) }}"
+41
View File
@@ -0,0 +1,41 @@
- name: Map test
hosts: localhost
vars:
namn: [
{
"fornamn": "Knatte",
"efternamn": "Anka",
"tel": 07012345678,
"adress": {
"stad": "Ankeborg",
"gata": "Ankvägen 1"
}
},
{
"fornamn": "Joakim",
"efternamn": "von Anka",
"tel": 070987654321,
"adress": {
"stad": "Ankeborg",
"gata": "Pengavägen 1"
},
},
{
"fornamn": "Oppfinnar-Jocke",
"efternamn": "Johansson",
"tel": 070123123123,
"adress": {
"stad": "Ankeborg",
"gata": "Laboratorievägen 1"
},
}]
tasks:
- name: Lista alla gator
debug:
msg="{{ namn | map(attribute='fornamn') }}"
- name: Lista alla städerna
debug:
msg="{{ namn | map(attribute='adress')
| map(attribute='gata') | join(', ') }}"
+28
View File
@@ -0,0 +1,28 @@
- hosts: localhost
vars:
num1: 5
num2: 10
lista: [2, 2, 9, 1, 5, 2, 1]
namn: ["Knatte", "Fnatte", "Knatte", "Knatte"]
tasks:
- name: Utföra aritmetik
debug:
msg: "{{ num1 * num2 }}"
- name: Hitta minsta talet
debug:
msg: "{{ lista|min }}"
- name: Hitta största talet
debug:
msg: "{{ lista|max }}"
- name: Lista bara unika tal
debug:
msg: "{{ lista|unique }}"
- name: Unique fungerar även på strängar
debug:
msg: "{{ namn|unique }}"
+20
View File
@@ -0,0 +1,20 @@
- hosts: localhost
vars:
text: Hej alla glada
num1: 5
num2: 10
tasks:
- name: Skriv ut variablerna
debug:
msg: "Texten är: {{ text }}. Talen är {{ num1 }}
och {{ num2 }}."
- name: Omvandla till versaler
debug:
msg: "{{ text|upper }}"
- name: Byt ut text och gör allt till gemener
debug:
msg: "{{ text|replace('glada','utvecklare')|lower }}"
+8
View File
@@ -0,0 +1,8 @@
- name: Extract test
hosts: localhost
tasks:
- name: Lista värdnamnen
debug:
msg: "{{ groups['ankeborg'] }}"
+12
View File
@@ -0,0 +1,12 @@
- name: Kör ett kommando om mer än 1500 mb ledigt minne
hosts: ankeborg
tasks:
- name: Kör echo
when: ansible_memfree_mb >= 1500
command:
cmd: echo "Bara ett test"
register: utdata
- name: Skriv ut utdata
debug:
var: utdata.stdout_lines
+7
View File
@@ -0,0 +1,7 @@
- name: Kör ett kommando om mer än 1500 mb ledigt minne
hosts: ankeborg
tasks:
- name: Kör echo
when: ansible_memfree_mb >= 1500
command:
cmd: echo "Bara ett test"
+1
View File
@@ -0,0 +1 @@
Hejsan
+1
View File
@@ -0,0 +1 @@
$6$WAFtsM1BDHKlAGcF$jyMA41xQONrF0y/EuydPutK.CfVCJzfIzdb8qnw.Q75oOMUMrUoNSXJ2rtzwvTjX2xAmz0FxUy51vS2tc8zVs/
+3
View File
@@ -0,0 +1,3 @@
dependencies:
- role: update_cache
+13
View File
@@ -0,0 +1,13 @@
- name: Install common tools
package:
name: "{{ item }}"
with_items:
- curl
- gnupg
- vim
- ca-certificates
- name: Set the timezone to Stockholm
timezone:
name: Europe/Stockholm
+13
View File
@@ -0,0 +1,13 @@
- name: Install common tools
package:
name: "{{ item }}"
with_items:
- curl
- gnupg
- vim
- ca-certificates
- name: Set the timezone to Stockholm
timezone:
name: Europe/Stockholm
+1
View File
@@ -0,0 +1 @@
my_number: 10
+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/python
from ansible.module_utils.basic import AnsibleModule
def run_module():
# definiera argument till modulen
module_args = dict(
number=dict(type='int', required=True),
)
# skapa en dict för resultatet
result = dict(
changed=False,
number=0,
)
# inställningar för modulen
module = AnsibleModule(
argument_spec=module_args,
supports_check_mode=False
)
# logiken för modulen
result['number'] = module.params['number']
if result['number'] > 50:
result['changed']=True
# returnera resultatet som json
module.exit_json(**result)
def main():
run_module()
if __name__ == '__main__':
main()
+4
View File
@@ -0,0 +1,4 @@
- name: Testa vår egna modul
dummy:
number: "{{ my_number }}"
+7
View File
@@ -0,0 +1,7 @@
mail_hostname: vm.nixnet.jke
canonical_name: vm.nixnet.example.tld
relay_host: email-smtp.eu-west-1.amazonaws.com
relay_port: 465
relay_user:
relay_password:
+14
View File
@@ -0,0 +1,14 @@
postmaster: root
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root
root: jake
jake: vm-mail@cyberinfo.se
+18
View File
@@ -0,0 +1,18 @@
- name: Activate and restart Postfix
service:
name: postfix
enabled: yes
state: restarted
- name: Generate SASL
command:
cmd: /usr/sbin/postmap /etc/postfix/sasl_passwd
- name: Generate aliases
command:
cmd: /usr/sbin/postalias /etc/aliases
- name: Generate sender_canonical
command:
cmd: /usr/sbin/postmap /etc/postfix/sender_canonical
+43
View File
@@ -0,0 +1,43 @@
- name: Check that a username and password is supplied
assert:
that:
- (relay_user is defined) and (relay_user is not none)
- (relay_password is defined) and
(relay_password is not none)
fail_msg: "'relay_user' and 'relay_password' must be set"
success_msg: "username and password for relay is set"
- name: Install Postfix and s-nail
package:
state: present
name: "{{ item }}"
with_items:
- postfix
- s-nail
notify: Activate and restart Postfix
- name: Configure Postfix
template:
src: main.cf.j2
dest: /etc/postfix/main cf
notify: Activate and restart Postfix
- name: Copy Postfix authentication
template:
src: sasl_passwd.j2
dest: /etc/postfix/sasl_passwd
mode: 0600
notify: Generate SASL
- name: Copy alisases
copy:
src: aliases
dest: /etc/aliases
notify: Generate aliases
- name: Copy sender_canonical
template:
src: sender_canonical.j2
dest: /etc/postfix/sender_canonical
notify: Generate sender_canonical
+29
View File
@@ -0,0 +1,29 @@
biff = no
append_dot_mydomain = no
compatibility_level = 2
myhostname = {{ mail_hostname }}
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = {{ mail_hostname }}
mydestination = $myhostname, {{ mail_hostname }}, localhost
relayhost = [{{ relay_host }}]:{{ relay_port }}
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = localhost
inet_protocols = all
# enable SASL authentication
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
# Enable STARTTLS encryption
smtp_use_tls = yes
smtp_tls_wrappermode = yes
smtp_tls_security_level = encrypt
# Setup sender canonical mapping
sender_canonical_maps = hash:/etc/postfix/sender_canonical
@@ -0,0 +1,2 @@
[{{ relay_host }}]:{{ relay_port }} {{ relay_user }}:{{ relay_password }}
@@ -0,0 +1,3 @@
root root@{{ canonical_name }}
jake jake@{{ canonical_name }}
+7
View File
@@ -0,0 +1,7 @@
mail_hostname: vm.nixnet.jke
canonical_name: vm.nixnet.example.tld
relay_host: email-smtp.eu-west-1.amazonaws.com
relay_port: 465
relay_user:
relay_password:
+14
View File
@@ -0,0 +1,14 @@
postmaster: root
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root
root: jake
jake: vm-mail@cyberinfo.se
+18
View File
@@ -0,0 +1,18 @@
- name: Activate and restart Postfix
service:
name: postfix
enabled: yes
state: restarted
- name: Generate SASL
command:
cmd: /usr/sbin/postmap /etc/postfix/sasl_passwd
- name: Generate aliases
command:
cmd: /usr/sbin/postalias /etc/aliases
- name: Generate sender_canonical
command:
cmd: /usr/sbin/postmap /etc/postfix/sender_canonical
+3
View File
@@ -0,0 +1,3 @@
dependencies:
- role: update_cache
+43
View File
@@ -0,0 +1,43 @@
- name: Check that a username and password is supplied
assert:
that:
- (relay_user is defined) and (relay_user is not none)
- (relay_password is defined) and
(relay_password is not none)
fail_msg: "'relay_user' and 'relay_password' must be set"
success_msg: "username and password for relay is set"
- name: Install Postfix and s-nail
package:
state: present
name: "{{ item }}"
with_items:
- postfix
- s-nail
notify: Activate and restart Postfix
- name: Configure Postfix
template:
src: main.cf.j2
dest: /etc/postfix/main cf
notify: Activate and restart Postfix
- name: Copy Postfix authentication
template:
src: sasl_passwd.j2
dest: /etc/postfix/sasl_passwd
mode: 0600
notify: Generate SASL
- name: Copy alisases
copy:
src: aliases
dest: /etc/aliases
notify: Generate aliases
- name: Copy sender_canonical
template:
src: sender_canonical.j2
dest: /etc/postfix/sender_canonical
notify: Generate sender_canonical
+29
View File
@@ -0,0 +1,29 @@
biff = no
append_dot_mydomain = no
compatibility_level = 2
myhostname = {{ mail_hostname }}
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = {{ mail_hostname }}
mydestination = $myhostname, {{ mail_hostname }}, localhost
relayhost = [{{ relay_host }}]:{{ relay_port }}
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = localhost
inet_protocols = all
# enable SASL authentication
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
# Enable STARTTLS encryption
smtp_use_tls = yes
smtp_tls_wrappermode = yes
smtp_tls_security_level = encrypt
# Setup sender canonical mapping
sender_canonical_maps = hash:/etc/postfix/sender_canonical
@@ -0,0 +1,2 @@
[{{ relay_host }}]:{{ relay_port }} {{ relay_user }}:{{ relay_password }}
@@ -0,0 +1,3 @@
root root@{{ canonical_name }}
jake jake@{{ canonical_name }}
+7
View File
@@ -0,0 +1,7 @@
mail_hostname: vm.nixnet.jke
canonical_name: vm.nixnet.example.tld
relay_host: email-smtp.eu-west-1.amazonaws.com
relay_port: 465
relay_user:
relay_password:
+14
View File
@@ -0,0 +1,14 @@
postmaster: root
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root
root: jake
jake: vm-mail@cyberinfo.se
+18
View File
@@ -0,0 +1,18 @@
- name: Activate and restart Postfix
service:
name: postfix
enabled: yes
state: restarted
- name: Generate SASL
command:
cmd: /usr/sbin/postmap /etc/postfix/sasl_passwd
- name: Generate aliases
command:
cmd: /usr/sbin/postalias /etc/aliases
- name: Generate sender_canonical
command:
cmd: /usr/sbin/postmap /etc/postfix/sender_canonical
+3
View File
@@ -0,0 +1,3 @@
dependencies:
- role: update_cache
@@ -0,0 +1,6 @@
- name: Configure Postfix
template:
src: main.cf.j2
dest: /etc/postfix/main.cf
notify: Activate and restart Postfix
+6
View File
@@ -0,0 +1,6 @@
- name: Copy alisases
copy:
src: aliases
dest: /etc/aliases
notify: Generate aliases
@@ -0,0 +1,7 @@
- name: Copy Postfix authentication
template:
src: sasl_passwd.j2
dest: /etc/postfix/sasl_passwd
mode: 0600
notify: Generate SASL
@@ -0,0 +1,6 @@
- name: Copy sender_canonical
template:
src: sender_canonical.j2
dest: /etc/postfix/sender_canonical
notify: Generate sender_canonical
@@ -0,0 +1,9 @@
- name: Install Postfix and s-nail
package:
state: present
name: "{{ item }}"
with_items:
- postfix
- s-nail
notify: Activate and restart Postfix
+15
View File
@@ -0,0 +1,15 @@
- name: Check that a username and password is supplied
assert:
that:
- (relay_user is defined) and (relay_user is not none)
- (relay_password is defined) and
(relay_password is not none)
fail_msg: "'relay_user' and 'relay_password' must be set"
success_msg: "username and password for relay is set"
- import_tasks: install-postfix.yml
- import_tasks: configure-postfix.yml
- import_tasks: copy-postfix-auth.yml
- import_tasks: copy-aliases.yml
- import_tasks: copy-sender-canonical.yml
+29
View File
@@ -0,0 +1,29 @@
biff = no
append_dot_mydomain = no
compatibility_level = 2
myhostname = {{ mail_hostname }}
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = {{ mail_hostname }}
mydestination = $myhostname, {{ mail_hostname }}, localhost
relayhost = [{{ relay_host }}]:{{ relay_port }}
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = localhost
inet_protocols = all
# enable SASL authentication
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
# Enable STARTTLS encryption
smtp_use_tls = yes
smtp_tls_wrappermode = yes
smtp_tls_security_level = encrypt
# Setup sender canonical mapping
sender_canonical_maps = hash:/etc/postfix/sender_canonical
@@ -0,0 +1,2 @@
[{{ relay_host }}]:{{ relay_port }} {{ relay_user }}:{{ relay_password }}
@@ -0,0 +1,3 @@
root root@{{ canonical_name }}
jake jake@{{ canonical_name }}
+14
View File
@@ -0,0 +1,14 @@
$ANSIBLE_VAULT;1.1;AES256
38326433663334316231393964323861326634316138663137343462303639383539613232633865
6462656338656163373330366635373431366638353365610a646133313831346534393736323737
38616533373133383766303538643635326535303232633837653737616362323432313964653837
6136306639613862340a316165623962356265646434383833303136656633656334343335633032
33346234633833363936383937623835313130373133626231326361666566636161353361616361
35323032383266643561636536616533333264613730623064663838346431353030393330336565
31653864396466303338626535343063633139383731326430356436626530373766353033366237
32343930373739306139643263306266333235383764656137326165646531646330383663306166
31376366366465663862383834343233363163383839663263393637353762346333663136633563
62393730363237666232353439623832623162363330616165653230653866663065613533393833
62343261356164653835383866343139303136316235323530356136663730613234383563653562
37346236366538366638633462326161333337316630333239643263303737663531373965386631
3834
+14
View File
@@ -0,0 +1,14 @@
postmaster: root
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root
root: jake
jake: vm-mail@cyberinfo.se
+18
View File
@@ -0,0 +1,18 @@
- name: Activate and restart Postfix
service:
name: postfix
enabled: yes
state: restarted
- name: Generate SASL
command:
cmd: /usr/sbin/postmap /etc/postfix/sasl_passwd
- name: Generate aliases
command:
cmd: /usr/sbin/postalias /etc/aliases
- name: Generate sender_canonical
command:
cmd: /usr/sbin/postmap /etc/postfix/sender_canonical
+34
View File
@@ -0,0 +1,34 @@
- name: Install Postfix and s-nail
package:
state: present
name: "{{ item }}"
with_items:
- postfix
- s-nail
notify: Activate and restart Postfix
- name: Configure Postfix
template:
src: main.cf.j2
dest: /etc/postfix/main.cf
notify: Activate and restart Postfix
- name: Copy Postfix authentication
template:
src: sasl_passwd.j2
dest: /etc/postfix/sasl_passwd
mode: 0600
notify: Generate SASL
- name: Copy alisases
copy:
src: aliases
dest: /etc/aliases
notify: Generate aliases
- name: Copy sender_canonical
template:
src: sender_canonical.j2
dest: /etc/postfix/sender_canonical
notify: Generate sender_canonical
+29
View File
@@ -0,0 +1,29 @@
biff = no
append_dot_mydomain = no
compatibility_level = 2
myhostname = {{ mail_hostname }}
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = {{ mail_hostname }}
mydestination = $myhostname, {{ mail_hostname }}, localhost
relayhost = [{{ relay_host }}]:{{ relay_port }}
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = localhost
inet_protocols = all
# enable SASL authentication
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
# Enable STARTTLS encryption
smtp_use_tls = yes
smtp_tls_wrappermode = yes
smtp_tls_security_level = encrypt
# Setup sender canonical mapping
sender_canonical_maps = hash:/etc/postfix/sender_canonical
+2
View File
@@ -0,0 +1,2 @@
[{{ relay_host }}]:{{ relay_port }} {{ relay_user }}:{{ relay_password }}
@@ -0,0 +1,3 @@
root root@{{ canonical_name }}
jake jake@{{ canonical_name }}
+9
View File
@@ -0,0 +1,9 @@
- name: Update cache on Debian/Ubuntu
apt:
update_cache: yes
when: ansible_os_family == 'Debian'
- name: Update cache on RedHat/CentOS/Fedora
dnf:
update_cache: yes
when: ansible_os_family == 'RedHat'
+5
View File
@@ -0,0 +1,5 @@
- name: Update Windows
ansible.windows.win_updates:
category_names: "*"
reboot: yes
+17
View File
@@ -0,0 +1,17 @@
- name: Sätt upp en webbsida med PHP-stöd
become: true
hosts: ankeborg
tasks:
- import_tasks: tasks/installera-apache-php.yml
- import_tasks: tasks/aktivera-apache.yml
- import_tasks: tasks/firewalld-http.yml
- import_tasks: tasks/skapa-webbsida.yml
- name: Testa webbservrarna
hosts: localhost
tasks:
- name: Anslut till servrarna
import_tasks: tasks/testa-webbservrarna.yml
vars:
min_grupp: ankeborg
+20
View File
@@ -0,0 +1,20 @@
- name: Sätt upp en webbsida med PHP-stöd
become: true
hosts: ankeborg
tasks:
- import_tasks: tasks/installera-apache-php-v3.yml
- import_tasks: tasks/skapa-webbsida-v3.yml
handlers:
- import_tasks: tasks/aktivera-apache.yml
- import_tasks: tasks/firewalld-http.yml
- import_tasks: tasks/radera-exempelsida-v3.yml
- name: Testa webbservrarna
hosts: localhost
tasks:
- name: Anslut till servrarna
import_tasks: tasks/testa-webbservrarna.yml
vars:
min_grupp: ankeborg
+67
View File
@@ -0,0 +1,67 @@
- name: Sätt upp en webbsida med PHP-stöd
become: true
hosts: ankeborg
tasks:
- name: Installera Apache och PHP i Debian
when: ansible_os_family == 'Debian'
apt:
update_cache: yes
name: "{{ item }}"
state: present
install_recommends: yes
with_items:
- apache2
- libapache2-mod-php
- name: Installera Apache och PHP i RedHat
when: ansible_os_family == 'RedHat'
dnf:
name: "{{ item }}"
state: present
update_cache: yes
install_weak_deps: yes
with_items:
- httpd
- php
- name: Aktivera Apache i Debian
when: ansible_os_family == 'Debian'
systemd:
name: apache2
enabled: yes
state: started
- name: Aktivera Apache i RedHat
when: ansible_os_family == 'RedHat'
systemd:
name: httpd
enabled: yes
state: started
- name: Öppna brandväggen i RedHat
when: ansible_os_family == 'RedHat'
firewalld:
service: http
permanent: yes
immediate: yes
state: enabled
- name: Ta bort eventuell exempelsida
file:
path: /var/www/html/index.html
state: absent
- name: Kopiera PHP-filen till värdarna
copy:
src: index.php
dest: /var/www/html/index.php
- name: Testa webbservrarna
hosts: localhost
tasks:
- name: Anslut till webbservrarna
uri:
url: "http://{{ item }}"
with_items: "{{ groups['ankeborg'] | map('extract', \
hostvars, ['ansible_host']) }}"
+18
View File
@@ -0,0 +1,18 @@
- name: Aktivera Apache i Debian
tags:
- apache
- systemd
systemd:
name: apache2
enabled: yes
state: started
- name: Aktivera Apache i RedHat
tags:
- apache
- systemd
systemd:
name: httpd
enabled: yes
state: started
+20
View File
@@ -0,0 +1,20 @@
- name: Aktivera Apache i Debian
tags:
- apache
- systemd
when: ansible_os_family == 'Debian'
systemd:
name: apache2
enabled: yes
state: started
- name: Aktivera Apache i RedHat
tags:
- apache
- systemd
when: ansible_os_family == 'RedHat'
systemd:
name: httpd
enabled: yes
state: started
+10
View File
@@ -0,0 +1,10 @@
- name: Öppna brandväggen i RedHat
tags:
- firewall
when: ansible_os_family == 'RedHat'
firewalld:
service: http
permanent: yes
immediate: yes
state: enabled
+9
View File
@@ -0,0 +1,9 @@
- name: Öppna brandväggen i RedHat
tags:
- firewall
firewalld:
service: http
permanent: yes
immediate: yes
state: enabled
+34
View File
@@ -0,0 +1,34 @@
- name: Installera Apache och PHP i Debian
tags:
- apache
- package
when: ansible_os_family == 'Debian'
apt:
update_cache: yes
name: "{{ item }}"
state: present
install_recommends: yes
with_items:
- apache2
- libapache2-mod-php
notify:
- Ta bort eventuell exempelsida
- Aktivera Apache i Debian
- name: Installera Apache och PHP i RedHat
tags:
- apache
- package
when: ansible_os_family == 'RedHat'
dnf:
name: "{{ item }}"
state: present
update_cache: yes
install_weak_deps: yes
with_items:
- httpd
- php
notify:
- Ta bort eventuell exempelsida
- Aktivera Apache i RedHat
- Öppna brandväggen i RedHat
+28
View File
@@ -0,0 +1,28 @@
- name: Installera Apache och PHP i Debian
tags:
- apache
- package
when: ansible_os_family == 'Debian'
apt:
update_cache: yes
name: "{{ item }}"
state: present
install_recommends: yes
with_items:
- apache2
- libapache2-mod-php
- name: Installera Apache och PHP i RedHat
tags:
- apache
- package
when: ansible_os_family == 'RedHat'
dnf:
name: "{{ item }}"
state: present
update_cache: yes
install_weak_deps: yes
with_items:
- httpd
- php
+8
View File
@@ -0,0 +1,8 @@
- name: Ta bort eventuell exempelsida
tags:
- index
- remove
file:
path: /var/www/html/index.html
state: absent
+8
View File
@@ -0,0 +1,8 @@
- name: Kopiera PHP-filen till värdarna
tags:
- index
- copy
copy:
src: ../files/index.php
dest: /var/www/html/index.php
+16
View File
@@ -0,0 +1,16 @@
- name: Ta bort eventuell exempelsida
tags:
- index
- remove
file:
path: /var/www/html/index.html
state: absent
- name: Kopiera PHP-filen till värdarna
tags:
- index
- copy
copy:
src: ../files/index.php
dest: /var/www/html/index.php
+8
View File
@@ -0,0 +1,8 @@
- name: Anslut till webbservrarna
tags:
- connect
uri:
url: "http://{{ item }}"
with_items: "{{ groups[min_grupp] | map('extract', \
hostvars, ['ansible_host']) }}"
+6
View File
@@ -0,0 +1,6 @@
- hosts: ankeborg
vars:
my_number: 45
roles:
- my_role
+10
View File
@@ -0,0 +1,10 @@
{% for item in namn %}
{% if item == "Joakim" %}
* {{ item }} är deras farbror
{% elif "tte" in item %}
* {{ item }} bor med {{ "kalle anka"|title }}
{% else %}
* {{ item }}
{% endif %}
{% endfor %}
+5
View File
@@ -0,0 +1,5 @@
* Knatte bor med Kalle Anka
* Tjatte bor med Kalle Anka
* Fnatte bor med Kalle Anka
* Joakim är deras farbror
+4
View File
@@ -0,0 +1,4 @@
{% for item in namn %}
* {{ item }}
{% endfor %}
+5
View File
@@ -0,0 +1,5 @@
* Knatte
* Tjatte
* Fnatte
* Joakim

Some files were not shown because too many files have changed in this diff Show More