Skip to content
Snippets Groups Projects
Commit e2a815c1 authored by poulpe's avatar poulpe
Browse files

[Update] Clean more output

parent a6893d83
No related branches found
No related tags found
No related merge requests found
...@@ -29,22 +29,35 @@ ...@@ -29,22 +29,35 @@
hosts: routeurs hosts: routeurs
become: yes become: yes
tasks: tasks:
- name: "Create file interface in interfaces.d"
ansible.builtin.template:
src: ./templates/router_config_template.j2
dest: /etc/network/interfaces.d/interfaces_playbook.conf
mode: 0640
notify: Restart network
- name: "Set ip_forwarding to 1" - name: "Set ip_forwarding to 1"
ansible.posix.sysctl: ansible.posix.sysctl:
name: net.ipv4.ip_forward name: net.ipv4.ip_forward
value: '1' value: '1'
sysctl_set: true sysctl_set: true
state: present state: present
- name: "Create file interface in interfaces.d"
ansible.builtin.template:
src: ./templates/router_config_template.j2
dest: /etc/network/interfaces.d/interfaces_playbook.conf
mode: 0640
notify: Restart network
handlers: handlers:
- name: Restart network - name: Restart network
ansible.builtin.service: ansible.builtin.service:
name: networking name: networking
state: restarted state: restarted
enabled: yes enabled: yes
- name: Display ping value
hosts: H1
become: yes
tasks:
- name: Ping form H1 to H2
ansible.builtin.shell: "ping 3.0.0.2 -c 1"
register: result
- name: Print result
debug:
msg: "{{ result.stdout_lines }}"
... ...
\ No newline at end of file
---
- name: Configuration et démarrage des interfaces réseau
hosts: all
become: true
tasks:
- name: Load the variables
include_vars: variables.yml
- name: Rename hosts
command: hostnamectl set-hostname {{ inventory_hostname }}
- name: Setup network for Hosts
hosts: hotes
become: yes
tasks:
- name: "Create file interface in interfaces.d"
ansible.builtin.template:
src: ./templates/host_config_template.j2
dest: /etc/network/interfaces.d/interfaces_playbook.conf
mode: 0640
- name: Setup network for Routers
hosts: routeurs
become: yes
tasks:
- name: "Create file interface in interfaces.d"
ansible.builtin.template:
src: ./templates/router_config_template.j2
dest: /etc/network/interfaces.d/interfaces_playbook.conf
mode: 0640
- name: "Set ip_forwarding to 1"
ansible.posix.sysctl:
name: net.ipv4.ip_forward
value: '1'
sysctl_set: true
state: present
- name: Configuration et démarrage des interfaces réseau
hosts: all
become: true
tasks:
- name: start network
service:
name: networking
state: restarted
enabled: yes
...
\ No newline at end of file
...@@ -127,17 +127,11 @@ ...@@ -127,17 +127,11 @@
src: ./templates/wireguard_config_template_H1.j2 src: ./templates/wireguard_config_template_H1.j2
dest: /etc/wireguard/wg0.conf dest: /etc/wireguard/wg0.conf
mode: 0640 mode: 0640
notify: wg-quick
handlers:
- name: wg-quick - name: wg-quick
ansible.builtin.shell: ansible.builtin.shell:
cmd: "wg-quick up wg0 2>/dev/null" cmd: "wg-quick up wg0 2>/dev/null"
- name: Test connectivity from H1 to H2
hosts: H1
tasks:
- name: Ping form H1 to H2 - name: Ping form H1 to H2
ansible.builtin.shell: "ping 3.0.0.2 -c 1" ansible.builtin.shell: "ping 3.0.0.2 -c 1"
register: result register: result
......
#!/bin/bash #!/bin/bash
# Create Key for H2 # Create Key for H2 ans save to pubkey_H1, privkey_H1
wg genkey > privkey_H2 wg genkey > privkey_H2
wg pubkey < privkey_H2 > pubkey_H2 wg pubkey < privkey_H2 > pubkey_H2
cat pubkey_H2 | xargs -i ansible-vault encrypt_string --vault-password-file vault_file {} --output pubkey_H2 cat pubkey_H2 | xargs -i ansible-vault encrypt_string --vault-password-file vault_file {} --output pubkey_H2
cat privkey_H2 | xargs -i ansible-vault encrypt_string --vault-password-file vault_file {} --output privkey_H2 cat privkey_H2 | xargs -i ansible-vault encrypt_string --vault-password-file vault_file {} --output privkey_H2
# Create Key for H1 # Create Key for H1 ans save to pubkey_H1, privkey_H1
wg genkey > privkey_H1 wg genkey > privkey_H1
wg pubkey < privkey_H1 > pubkey_H1 wg pubkey < privkey_H1 > pubkey_H1
cat pubkey_H1 | xargs -i ansible-vault encrypt_string --vault-password-file vault_file {} --output pubkey_H1 cat pubkey_H1 | xargs -i ansible-vault encrypt_string --vault-password-file vault_file {} --output pubkey_H1
cat privkey_H1 | xargs -i ansible-vault encrypt_string --vault-password-file vault_file {} --output privkey_H1 cat privkey_H1 | xargs -i ansible-vault encrypt_string --vault-password-file vault_file {} --output privkey_H1
# echo "H2:" > keys.yml # Create H2 keys in keys.yml
echo "---" > keys.yml echo "---" > keys.yml
echo "keys:" >> keys.yml echo "keys:" >> keys.yml
echo " H2PRIV: $(cat privkey_H2 )" >> keys.yml echo " H2PRIV: $(cat privkey_H2 )" >> keys.yml
echo " H2PUB: $(cat pubkey_H2 )" >> keys.yml echo " H2PUB: $(cat pubkey_H2 )" >> keys.yml
# echo "H1:" >> keys.yml # Create H1 keys in keys.yml
echo " H1PRIV: $(cat privkey_H1 )" >> keys.yml echo " H1PRIV: $(cat privkey_H1 )" >> keys.yml
echo " H1PUB: $(cat pubkey_H1 )" >> keys.yml echo " H1PUB: $(cat pubkey_H1 )" >> keys.yml
\ No newline at end of file
#!/usr/sbin/nft -f
table ip filter {
chain FORWARD {
type filter hook forward priority 0; policy accept;
iifname "wg0" counter accept
}
chain POSTROUTING {
type filter hook postrouting priority 0; policy accept;
oifname "eth0" counter masquerade
}
}
!vault |
$ANSIBLE_VAULT;1.1;AES256
34323537383365663838666331323431393337303565396339353930333239666636363036383362
6664653063393737353638303964616639336264373931350a626635376437636136666231303930
61313438346230373835616563323433633534343934393131613161353337656163643930626366
6261303163613732370a366636353564393036643264376135616166646166663438636436663462
36653865326135646362323166616332343363323461303831386331616662313363653831666664
3764666134353061313162336364396633353739333234373630
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment