Skip to content

Commit

Permalink
~/.ssh/configをJinja2化、伴ってnetworkのディクショナリを変更
Browse files Browse the repository at this point in the history
  • Loading branch information
cradle8810 committed Apr 28, 2024
1 parent 6f2c904 commit 9e75b2c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
5 changes: 4 additions & 1 deletion inventories/host_vars/networks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion inventories/host_vars/rui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions macbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@
tags:
- symlink
- symlinks

- name: Put ~/.ssh/config
ansible.builtin.import_tasks:
file: tasks/macbook/home_ssh_config.yml
tags:
- ssh
8 changes: 8 additions & 0 deletions tasks/macbook/home_ssh_config.yml
Original file line number Diff line number Diff line change
@@ -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'
15 changes: 15 additions & 0 deletions templates/mac/Users/hayato/.ssh/config.j2
Original file line number Diff line number Diff line change
@@ -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 %}
2 changes: 1 addition & 1 deletion templates/rui/etc/dnsmasq.d/resolv.txt.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% for resolver in network.dns4 %}
{% for resolver in subnet.dns4 %}
server={{ resolver }}
{% endfor %}

0 comments on commit 9e75b2c

Please sign in to comment.