From 9e75b2c44e4ac999f38ea283ae1a2545ce55fc66 Mon Sep 17 00:00:00 2001 From: Hayato Date: Sun, 28 Apr 2024 19:19:45 +0900 Subject: [PATCH] =?UTF-8?q?~/.ssh/config=E3=82=92Jinja2=E5=8C=96=E3=80=81?= =?UTF-8?q?=E4=BC=B4=E3=81=A3=E3=81=A6network=E3=81=AE=E3=83=87=E3=82=A3?= =?UTF-8?q?=E3=82=AF=E3=82=B7=E3=83=A7=E3=83=8A=E3=83=AA=E3=82=92=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inventories/host_vars/networks.yml | 5 ++++- inventories/host_vars/rui.yml | 2 +- macbook.yml | 6 ++++++ tasks/macbook/home_ssh_config.yml | 8 ++++++++ templates/mac/Users/hayato/.ssh/config.j2 | 15 +++++++++++++++ templates/rui/etc/dnsmasq.d/resolv.txt.j2 | 2 +- 6 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 tasks/macbook/home_ssh_config.yml create mode 100644 templates/mac/Users/hayato/.ssh/config.j2 diff --git a/inventories/host_vars/networks.yml b/inventories/host_vars/networks.yml index 069d7b9..0bd9af4 100644 --- a/inventories/host_vars/networks.yml +++ b/inventories/host_vars/networks.yml @@ -48,7 +48,10 @@ network: macbook: hostname: HayabookAir2023.hayaworld.local shortname: HayabookAir2023 - subnet: 24 + + +subnet: + mask: 24 gw4: 192.168.1.1 dns4: - 192.168.1.100 diff --git a/inventories/host_vars/rui.yml b/inventories/host_vars/rui.yml index c86e6ab..71d08de 100644 --- a/inventories/host_vars/rui.yml +++ b/inventories/host_vars/rui.yml @@ -30,7 +30,7 @@ dnsmasq: dhcp_option: ntp_server: 210.130.188.10 dns_server: "{{ network.rui.ipv4 }}" - router: "{{ network.gw4 }}" + router: "{{ subnet.gw4 }}" netmask: "255.255.255.0" dns: cache_size: 4000 diff --git a/macbook.yml b/macbook.yml index b148f1d..ee94d50 100644 --- a/macbook.yml +++ b/macbook.yml @@ -29,3 +29,9 @@ tags: - symlink - symlinks + + - name: Put ~/.ssh/config + ansible.builtin.import_tasks: + file: tasks/macbook/home_ssh_config.yml + tags: + - ssh diff --git a/tasks/macbook/home_ssh_config.yml b/tasks/macbook/home_ssh_config.yml new file mode 100644 index 0000000..d9dc1b1 --- /dev/null +++ b/tasks/macbook/home_ssh_config.yml @@ -0,0 +1,8 @@ +--- +- name: Add User ssh config + ansible.builtin.template: + src: templates/mac/Users/hayato/.ssh/config.j2 + dest: /Users/hayato/.ssh/config + owner: hayato + group: staff + mode: '0644' diff --git a/templates/mac/Users/hayato/.ssh/config.j2 b/templates/mac/Users/hayato/.ssh/config.j2 new file mode 100644 index 0000000..e603b12 --- /dev/null +++ b/templates/mac/Users/hayato/.ssh/config.j2 @@ -0,0 +1,15 @@ +AddKeysToAgent yes +UseKeychain yes +IdentityFile ~/.ssh/id_ed25519 + +Host github.com + Hostname ssh.github.com + Port 443 + +{% for host in network.values() %} +Host {{ host.shortname }} + Hostname {{ host.hostname }} + Port 22 + User hayato + +{% endfor %} diff --git a/templates/rui/etc/dnsmasq.d/resolv.txt.j2 b/templates/rui/etc/dnsmasq.d/resolv.txt.j2 index f15eac5..7431c77 100644 --- a/templates/rui/etc/dnsmasq.d/resolv.txt.j2 +++ b/templates/rui/etc/dnsmasq.d/resolv.txt.j2 @@ -1,3 +1,3 @@ -{% for resolver in network.dns4 %} +{% for resolver in subnet.dns4 %} server={{ resolver }} {% endfor %}