Skip to content

Commit 866fc8c

Browse files
committed
new parameter: node_write_etc_hosts
1 parent 418f240 commit 866fc8c

File tree

8 files changed

+46
-18
lines changed

8 files changed

+46
-18
lines changed

docs/NODE.md

+1
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ There are 11 sections, 66 parameters about [`NODE`](PARAM#node) module.
420420
| [`nodename_overwrite`](PARAM#nodename_overwrite) | [`NODE_ID`](PARAM#node_id) | bool | C | overwrite node's hostname with nodename? |
421421
| [`nodename_exchange`](PARAM#nodename_exchange) | [`NODE_ID`](PARAM#node_id) | bool | C | exchange nodename among play hosts? |
422422
| [`node_id_from_pg`](PARAM#node_id_from_pg) | [`NODE_ID`](PARAM#node_id) | bool | C | use postgres identity as node identity if applicable? |
423+
| [`node_write_etc_hosts`](PARAM#node_write_etc_hosts) | [`NODE_DNS`](PARAM#node_dns) | bool | G/C/I | modify `/etc/hosts` on target node? |
423424
| [`node_default_etc_hosts`](PARAM#node_default_etc_hosts) | [`NODE_DNS`](PARAM#node_dns) | string[] | G | static dns records in `/etc/hosts` |
424425
| [`node_etc_hosts`](PARAM#node_etc_hosts) | [`NODE_DNS`](PARAM#node_dns) | string[] | C | extra static dns records in `/etc/hosts` |
425426
| [`node_dns_method`](PARAM#node_dns_method) | [`NODE_DNS`](PARAM#node_dns) | enum | C | how to handle dns servers: add,none,overwrite |

docs/PARAM.md

+17-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@
6565
| 203 | [`nodename_overwrite`](#nodename_overwrite) | [`NODE`](#node) | [`NODE_ID`](#node_id) | bool | C | overwrite node's hostname with nodename? |
6666
| 204 | [`nodename_exchange`](#nodename_exchange) | [`NODE`](#node) | [`NODE_ID`](#node_id) | bool | C | exchange nodename among play hosts? |
6767
| 205 | [`node_id_from_pg`](#node_id_from_pg) | [`NODE`](#node) | [`NODE_ID`](#node_id) | bool | C | use postgres identity as node identity if applicable? |
68-
| 210 | [`node_default_etc_hosts`](#node_default_etc_hosts) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | G | static dns records in `/etc/hosts` |
69-
| 211 | [`node_etc_hosts`](#node_etc_hosts) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | C | extra static dns records in `/etc/hosts` |
70-
| 212 | [`node_dns_method`](#node_dns_method) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | enum | C | how to handle dns servers: add,none,overwrite |
71-
| 213 | [`node_dns_servers`](#node_dns_servers) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | C | dynamic nameserver in `/etc/resolv.conf` |
72-
| 214 | [`node_dns_options`](#node_dns_options) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | C | dns resolv options in `/etc/resolv.conf` |
68+
| 210 | [`node_write_etc_hosts`](PARAM#node_write_etc_hosts) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | bool | G/C/I | modify `/etc/hosts` on target node? |
69+
| 211 | [`node_default_etc_hosts`](#node_default_etc_hosts) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | G | static dns records in `/etc/hosts` |
70+
| 212 | [`node_etc_hosts`](#node_etc_hosts) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | C | extra static dns records in `/etc/hosts` |
71+
| 213 | [`node_dns_method`](#node_dns_method) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | enum | C | how to handle dns servers: add,none,overwrite |
72+
| 214 | [`node_dns_servers`](#node_dns_servers) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | C | dynamic nameserver in `/etc/resolv.conf` |
73+
| 215 | [`node_dns_options`](#node_dns_options) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | C | dns resolv options in `/etc/resolv.conf` |
7374
| 220 | [`node_repo_modules`](#node_repo_modules) | [`NODE`](#node) | [`NODE_PACKAGE`](#node_package) | string | C | upstream repo to be added on node, local by default |
7475
| 221 | [`node_repo_remove`](#node_repo_remove) | [`NODE`](#node) | [`NODE_PACKAGE`](#node_package) | bool | C | remove existing repo on node? |
7576
| 223 | [`node_packages`](#node_packages) | [`NODE`](#node) | [`NODE_PACKAGE`](#node_package) | string[] | C | packages to be installed current nodes |
@@ -1528,6 +1529,7 @@ Pigsty configs static DNS records and dynamic DNS resolver for nodes.
15281529
If you already have a DNS server, set [`node_dns_method`](#node_dns_method) to `none` to disable dynamic DNS setup.
15291530

15301531
```yaml
1532+
node_write_etc_hosts: true # modify `/etc/hosts` on target node?
15311533
node_default_etc_hosts: # static dns records in `/etc/hosts`
15321534
- "${admin_ip} h.pigsty a.pigsty p.pigsty g.pigsty"
15331535
node_etc_hosts: [] # extra static dns records in `/etc/hosts`
@@ -1538,6 +1540,16 @@ node_dns_options: # dns resolv options in `/etc/resolv.conf`
15381540
```
15391541
15401542
1543+
1544+
### node_write_etc_hosts
1545+
1546+
name: `node_write_etc_hosts`, type: 'bool', level: `G|C|I`
1547+
1548+
modify `/etc/hosts` on target node?
1549+
1550+
1551+
1552+
15411553
### `node_default_etc_hosts`
15421554

15431555
name: `node_default_etc_hosts`, type: `string[]`, level: `G`

docs/zh/PARAM.md

+16-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@
6565
| 203 | [`nodename_overwrite`](#nodename_overwrite) | [`NODE`](#node) | [`NODE_ID`](#node_id) | bool | C | 用 nodename 覆盖节点的主机名吗? |
6666
| 204 | [`nodename_exchange`](#nodename_exchange) | [`NODE`](#node) | [`NODE_ID`](#node_id) | bool | C | 在剧本主机之间交换 nodename 吗? |
6767
| 205 | [`node_id_from_pg`](#node_id_from_pg) | [`NODE`](#node) | [`NODE_ID`](#node_id) | bool | C | 如果可行,是否借用 postgres 身份作为节点身份? |
68-
| 210 | [`node_default_etc_hosts`](#node_default_etc_hosts) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | G | /etc/hosts 中的静态 DNS 记录 |
69-
| 211 | [`node_etc_hosts`](#node_etc_hosts) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | C | /etc/hosts 中的额外静态 DNS 记录 |
70-
| 212 | [`node_dns_method`](#node_dns_method) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | enum | C | 如何处理现有DNS服务器:add,none,overwrite |
71-
| 213 | [`node_dns_servers`](#node_dns_servers) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | C | /etc/resolv.conf 中的动态域名服务器列表 |
72-
| 214 | [`node_dns_options`](#node_dns_options) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | C | /etc/resolv.conf 中的DNS解析选项 |
68+
| 210 | [`node_write_etc_hosts`](#node_write_etc_hosts) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | bool | G/C/I | 是否修改目标节点上的 `/etc/hosts`|
69+
| 211 | [`node_default_etc_hosts`](#node_default_etc_hosts) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | G | /etc/hosts 中的静态 DNS 记录 |
70+
| 212 | [`node_etc_hosts`](#node_etc_hosts) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | C | /etc/hosts 中的额外静态 DNS 记录 |
71+
| 213 | [`node_dns_method`](#node_dns_method) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | enum | C | 如何处理现有DNS服务器:add,none,overwrite |
72+
| 214 | [`node_dns_servers`](#node_dns_servers) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | C | /etc/resolv.conf 中的动态域名服务器列表 |
73+
| 215 | [`node_dns_options`](#node_dns_options) | [`NODE`](#node) | [`NODE_DNS`](#node_dns) | string[] | C | /etc/resolv.conf 中的DNS解析选项 |
7374
| 220 | [`node_repo_modules`](#node_repo_modules) | [`NODE`](#node) | [`NODE_PACKAGE`](#node_package) | enum | C | 在节点上启用哪些软件源模块?默认为 local 使用本地源 |
7475
| 221 | [`node_repo_remove`](#node_repo_remove) | [`NODE`](#node) | [`NODE_PACKAGE`](#node_package) | bool | C | 配置节点软件仓库时,删除节点上现有的仓库吗? |
7576
| 223 | [`node_packages`](#node_packages) | [`NODE`](#node) | [`NODE_PACKAGE`](#node_package) | string[] | C | 要在当前节点上安装的软件包列表 |
@@ -1567,6 +1568,7 @@ Pigsty会为节点配置静态DNS解析记录与动态DNS服务器。
15671568
如果您的节点供应商已经为您配置了DNS服务器,您可以将 [`node_dns_method`](#node_dns_method) 设置为 `none` 跳过DNS设置。
15681569

15691570
```yaml
1571+
node_write_etc_hosts: true # modify `/etc/hosts` on target node?
15701572
node_default_etc_hosts: # static dns records in `/etc/hosts`
15711573
- "${admin_ip} h.pigsty a.pigsty p.pigsty g.pigsty"
15721574
node_etc_hosts: [] # extra static dns records in `/etc/hosts`
@@ -1578,6 +1580,15 @@ node_dns_options: # dns resolv options in `/etc/resolv.conf`
15781580
15791581
15801582
1583+
### node_write_etc_hosts
1584+
1585+
参数名称: `node_write_etc_hosts`, 类型: `bool`, 层次:`G|C|I`
1586+
1587+
是否修改目标节点上的 `/etc/hosts`?例如,在容器环境中通常不允许修改此配置文件。
1588+
1589+
1590+
1591+
15811592
### `node_default_etc_hosts`
15821593

15831594
参数名称: `node_default_etc_hosts`, 类型: `string[]`, 层次:`G`

files/cmdb.sql

+6-5
Original file line numberDiff line numberDiff line change
@@ -1311,11 +1311,12 @@ INSERT INTO pigsty.default_var VALUES
13111311
(204, 'nodename_exchange', 'false', 'NODE', 'NODE_ID', 'bool', 'C', 'exchange nodename among play hosts?', NULL),
13121312
(205, 'node_id_from_pg', 'true', 'NODE', 'NODE_ID', 'bool', 'C', 'use postgres identity as node identity if applicable?', NULL),
13131313

1314-
(210, 'node_default_etc_hosts', '["${admin_ip} h.pigsty a.pigsty p.pigsty g.pigsty"]', 'NODE', 'NODE_DNS', 'string[]', 'G', 'static dns records in `/etc/hosts`', NULL),
1315-
(211, 'node_etc_hosts', '[]', 'NODE', 'NODE_DNS', 'string[]', 'C', 'extra static dns records in `/etc/hosts`', NULL),
1316-
(212, 'node_dns_method', '"add"', 'NODE', 'NODE_DNS', 'enum', 'C', 'how to handle dns servers: add,none,overwrite', NULL),
1317-
(213, 'node_dns_servers', '["${admin_ip}"]', 'NODE', 'NODE_DNS', 'string[]', 'C', 'dynamic nameserver in `/etc/resolv.conf`', NULL),
1318-
(214, 'node_dns_options', '["options single-request-reopen timeout:1"]', 'NODE', 'NODE_DNS', 'string[]', 'C', 'dns resolv options in `/etc/resolv.conf`', NULL),
1314+
(210, 'node_write_etc_hosts', 'true', 'NODE', 'NODE_DNS', 'bool', 'G|C|I', 'modify `/etc/hosts on target node?', NULL),
1315+
(211, 'node_default_etc_hosts', '["${admin_ip} h.pigsty a.pigsty p.pigsty g.pigsty"]', 'NODE', 'NODE_DNS', 'string[]', 'G', 'static dns records in `/etc/hosts`', NULL),
1316+
(212, 'node_etc_hosts', '[]', 'NODE', 'NODE_DNS', 'string[]', 'C', 'extra static dns records in `/etc/hosts`', NULL),
1317+
(213, 'node_dns_method', '"add"', 'NODE', 'NODE_DNS', 'enum', 'C', 'how to handle dns servers: add,none,overwrite', NULL),
1318+
(214, 'node_dns_servers', '["${admin_ip}"]', 'NODE', 'NODE_DNS', 'string[]', 'C', 'dynamic nameserver in `/etc/resolv.conf`', NULL),
1319+
(215, 'node_dns_options', '["options single-request-reopen timeout:1"]', 'NODE', 'NODE_DNS', 'string[]', 'C', 'dns resolv options in `/etc/resolv.conf`', NULL),
13191320

13201321
(220, 'node_repo_modules', '"local"', 'NODE', 'NODE_PACKAGE', 'string', 'C/A', 'upstream repo to be added on node, local by default', NULL),
13211322
(221, 'node_repo_remove', 'true', 'NODE', 'NODE_PACKAGE', 'bool', 'C/A', 'remove existing repo on node?', NULL),

files/pigsty/full.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# File : full.yml
44
# Desc : pigsty demo config with full default values
55
# Ctime : 2020-05-22
6-
# Mtime : 2024-02-19
6+
# Mtime : 2024-04-27
77
# Docs : https://pigsty.io/docs/setup/config/
88
# Author : Ruohang Feng ([email protected])
99
# License : AGPLv3
@@ -368,6 +368,7 @@ all:
368368
#-----------------------------------------------------------------
369369
# NODE_DNS
370370
#-----------------------------------------------------------------
371+
node_write_etc_hosts: true # modify `/etc/hosts` on target node?
371372
node_default_etc_hosts: # static dns records in `/etc/hosts`
372373
- "${admin_ip} h.pigsty a.pigsty p.pigsty g.pigsty"
373374
node_etc_hosts: [] # extra static dns records in `/etc/hosts`

pigsty.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# File : pigsty.yml
44
# Desc : pigsty complete config example
55
# Ctime : 2020-05-22
6-
# Mtime : 2024-02-20
6+
# Mtime : 2024-04-27
77
# Docs : https://pigsty.io/docs/setup/config/
88
# Author : Ruohang Feng ([email protected])
99
# License : AGPLv3
@@ -365,6 +365,7 @@ all:
365365
#-----------------------------------------------------------------
366366
# NODE_DNS
367367
#-----------------------------------------------------------------
368+
node_write_etc_hosts: true # modify `/etc/hosts` on target node?
368369
node_default_etc_hosts: # static dns records in `/etc/hosts`
369370
- "${admin_ip} h.pigsty a.pigsty p.pigsty g.pigsty"
370371
node_etc_hosts: [] # extra static dns records in `/etc/hosts`

roles/node/defaults/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ node_id_from_pg: true # use postgres identity as node identity if ap
1111
#-----------------------------------------------------------------
1212
# NODE_DNS
1313
#-----------------------------------------------------------------
14+
node_write_etc_hosts: true # modify `/etc/hosts` on target node?
1415
node_default_etc_hosts: # static dns records in `/etc/hosts`
1516
- "${admin_ip} h.pigsty a.pigsty p.pigsty g.pigsty"
1617
node_etc_hosts: [] # extra static dns records in `/etc/hosts`

roles/node/tasks/dns.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#--------------------------------------------------------------#
55
- name: setup node dns
66
tags: node_hosts
7+
when: node_write_etc_hosts|bool
78
block:
89

910
# NOTE: dns records suffixed with "# pigsty meta" will be treated as meta node dns record and been wiped
@@ -64,5 +65,4 @@
6465
{% endif %}
6566
{% endfor %}
6667
{% endif %}
67-
...
6868
...

0 commit comments

Comments
 (0)