Skip to content

Commit 2a75304

Browse files
authored
Merge pull request #18 from p3lim/hostrecord
Add support for enrolling host with DNS records
2 parents 2570140 + d78f81f commit 2a75304

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

freeipa/client/init.sls

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,54 @@ freeipa_get_ticket:
2525
- file: freeipa_push_principal
2626
- onchanges:
2727
- file: freeipa_push_principal
28+
{%- if client.ip is defined %}
29+
{%- set client_ip = client.get("ip") %}
30+
freeipa_dnsrecord_add:
31+
cmd.run:
32+
- name: >
33+
curl -k -s
34+
-H referer:https://{{ ipa_servers[0] }}/ipa
35+
--negotiate -u :
36+
-H "Content-Type:application/json"
37+
-H "Accept:application/json"
38+
-c /tmp/cookiejar -b /tmp/cookiejar
39+
--output /dev/stderr
40+
--write-out "%{http_code}"
41+
-X POST
42+
-d '{
43+
"id": 0,
44+
"method": "dnsrecord_add",
45+
"params": [
46+
[
47+
"{{ client.get("domain", {}) }}",
48+
{
49+
"__dns_name__": "{{ client.get("hostname", {}).replace(client.get("domain", {}), "")[:-1] }}"
50+
}
51+
],
52+
{
53+
{%- if client_ip.get("reverse", True) %}
54+
{%- if client_ip.get("aaaa") %}
55+
"aaaa_extra_create_reverse": true,
56+
{%- else %}
57+
"a_extra_create_reverse": true,
58+
{%- endif %}
59+
{%- endif %}
60+
{%- if client_ip.get("aaaa") %}
61+
"aaaa_part_ip_address": "{{ client_ip.get("aaaa") }}",
62+
{%- else %}
63+
"a_part_ip_address": "{{ client_ip.get("a", salt.grains.get("fqdn_ip4", [])[0]) }}",
64+
{%- endif %}
65+
"version": "2.156"
66+
}
67+
]
68+
}' https://{{ ipa_servers[0] }}/ipa/json | awk '{if ($0<200||$0>399) exit $0}'
69+
- require:
70+
- cmd: freeipa_get_ticket
71+
- require_in:
72+
- cmd: freeipa_client_install
73+
- onchanges:
74+
- file: freeipa_push_principal
75+
{%- endif %}
2876
freeipa_host_add:
2977
cmd.run:
3078
- name: >
@@ -34,6 +82,8 @@ freeipa_host_add:
3482
-H "Content-Type:application/json"
3583
-H "Accept:applicaton/json"
3684
-c /tmp/cookiejar -b /tmp/cookiejar
85+
--output /dev/stderr
86+
--write-out "%{http_code}"
3787
-X POST
3888
-d '{
3989
"id": 0,
@@ -53,9 +103,12 @@ freeipa_host_add:
53103
"version": "2.156"
54104
}
55105
]
56-
}' https://{{ ipa_servers[0] }}/ipa/json
106+
}' https://{{ ipa_servers[0] }}/ipa/json | awk '{if ($0<200||$0>399) exit $0}'
57107
- require:
58108
- cmd: freeipa_get_ticket
109+
{%- if client.ip is defined %}
110+
- cmd: freeipa_dnsrecord_add
111+
{%- endif %}
59112
- require_in:
60113
- cmd: freeipa_client_install
61114
- onchanges:

0 commit comments

Comments
 (0)