@yawlabs/ansible-mcp 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context.d.ts +4 -0
- package/dist/exec.d.ts +10 -2
- package/dist/index.js +559 -299
- package/dist/playbook.d.ts +12 -0
- package/dist/project.d.ts +30 -3
- package/dist/redact.d.ts +7 -0
- package/dist/server.js +569 -300
- package/dist/upgrade.d.ts +3 -0
- package/dist/yaml.d.ts +1 -0
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -8,203 +8,6 @@ import { createHash } from "crypto";
|
|
|
8
8
|
import { existsSync as existsSync2, statSync } from "fs";
|
|
9
9
|
import { resolve } from "path";
|
|
10
10
|
|
|
11
|
-
// src/ansibleDoc.ts
|
|
12
|
-
var asText = (d) => Array.isArray(d) ? d.map(String).join(" ") : typeof d === "string" ? d : d === void 0 || d === null ? "" : String(d);
|
|
13
|
-
function parseDocJson(text2) {
|
|
14
|
-
const out = /* @__PURE__ */ new Map();
|
|
15
|
-
const t = text2.trim();
|
|
16
|
-
if (!t) return out;
|
|
17
|
-
let data;
|
|
18
|
-
try {
|
|
19
|
-
data = JSON.parse(t);
|
|
20
|
-
} catch (e) {
|
|
21
|
-
throw new Error(`ansible-doc --json did not return JSON (${e instanceof Error ? e.message : String(e)}).`);
|
|
22
|
-
}
|
|
23
|
-
for (const [key, entry] of Object.entries(data ?? {})) {
|
|
24
|
-
const doc = entry?.doc;
|
|
25
|
-
if (!doc || typeof doc !== "object") continue;
|
|
26
|
-
out.set(key, {
|
|
27
|
-
key,
|
|
28
|
-
fqcn: String(doc.plugin_name ?? key),
|
|
29
|
-
collection: String(doc.collection ?? ""),
|
|
30
|
-
filename: String(doc.filename ?? ""),
|
|
31
|
-
hasAction: doc.has_action === true,
|
|
32
|
-
shortDescription: asText(doc.short_description),
|
|
33
|
-
description: asText(doc.description),
|
|
34
|
-
options: doc.options ?? {},
|
|
35
|
-
deprecated: doc.deprecated && typeof doc.deprecated === "object" ? doc.deprecated : void 0,
|
|
36
|
-
checkMode: doc.attributes?.check_mode?.support,
|
|
37
|
-
requirements: Array.isArray(doc.requirements) ? doc.requirements.map(String) : [],
|
|
38
|
-
returns: entry.return && typeof entry.return === "object" ? entry.return : null,
|
|
39
|
-
examples: typeof entry.examples === "string" ? entry.examples : "",
|
|
40
|
-
versionAdded: doc.version_added
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
return out;
|
|
44
|
-
}
|
|
45
|
-
var TOMBSTONE = /\[ERROR\]: (?:\w+ )?(\S+) Missing documentation \(or could not parse documentation\): (?:The '[^']+' \w+ has been removed\. )?(.*?) ?This feature was removed from collection '([^']+)' version ([^\s]+?)\.?$/;
|
|
46
|
-
function classifyDocStderr(stderr) {
|
|
47
|
-
const r = { missing: [], deprecations: [], tombstones: [], errors: [] };
|
|
48
|
-
for (const line of stderr.split(/\r?\n/)) {
|
|
49
|
-
let m = /^\[WARNING\]: (\S+) was not found$/.exec(line);
|
|
50
|
-
if (m) {
|
|
51
|
-
if (!r.missing.includes(m[1])) r.missing.push(m[1]);
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
m = /^\[DEPRECATION WARNING\]: (\S+) has been deprecated\. (.*)$/.exec(line);
|
|
55
|
-
if (m) {
|
|
56
|
-
r.deprecations.push({ name: m[1], text: m[2] });
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
m = TOMBSTONE.exec(line);
|
|
60
|
-
if (m) {
|
|
61
|
-
if (!r.tombstones.some((t) => t.name === m[1])) {
|
|
62
|
-
r.tombstones.push({ name: m[1], text: m[2].trim(), collection: m[3], version: m[4] });
|
|
63
|
-
}
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (line.startsWith("[ERROR]:")) r.errors.push(line.slice(9).trim());
|
|
67
|
-
}
|
|
68
|
-
return r;
|
|
69
|
-
}
|
|
70
|
-
function choicesOf(o) {
|
|
71
|
-
if (!o?.choices) return null;
|
|
72
|
-
return Array.isArray(o.choices) ? o.choices : Object.keys(o.choices);
|
|
73
|
-
}
|
|
74
|
-
function subOptionsOf(o) {
|
|
75
|
-
return o?.suboptions ?? o?.options ?? null;
|
|
76
|
-
}
|
|
77
|
-
var typeOf = (o) => o?.type ?? "str";
|
|
78
|
-
function findOption(options, name) {
|
|
79
|
-
if (Object.hasOwn(options, name)) return [name, options[name], void 0];
|
|
80
|
-
for (const [k, o] of Object.entries(options)) {
|
|
81
|
-
if (o.aliases?.includes(name)) return [k, o, name];
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
function oneLine(desc, max) {
|
|
86
|
-
let d = asText(desc).replace(/\s+/g, " ").trim();
|
|
87
|
-
if (max && d.length > max) d = `${d.slice(0, max)}...`;
|
|
88
|
-
return d;
|
|
89
|
-
}
|
|
90
|
-
var fmtDefault = (v) => JSON.stringify(v);
|
|
91
|
-
function optionLine(name, o, pad, descLen, majorFloor) {
|
|
92
|
-
const t = typeOf(o);
|
|
93
|
-
const type = o.elements ? `${t} of ${o.elements}` : t;
|
|
94
|
-
const flags = [];
|
|
95
|
-
if (o.required) flags.push("[required]");
|
|
96
|
-
if (o.default !== void 0 && o.default !== null)
|
|
97
|
-
flags.push(o.no_log ? "[default: (no_log)]" : `[default: ${fmtDefault(o.default)}]`);
|
|
98
|
-
const ch = choicesOf(o);
|
|
99
|
-
if (ch) flags.push(`[choices: ${ch.map((c) => String(c)).join("|")}]`);
|
|
100
|
-
if (o.aliases?.length) flags.push(`[aliases: ${o.aliases.join(", ")}]`);
|
|
101
|
-
if (o.no_log) flags.push("[no_log]");
|
|
102
|
-
if (o.deprecated) {
|
|
103
|
-
const d = o.deprecated;
|
|
104
|
-
flags.push(
|
|
105
|
-
`[deprecated${d.removed_in ? `: removed in ${d.removed_in}` : ""}${d.alternative ? `, ${oneLine(d.alternative, 80)}` : ""}]`
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
if (o.version_added && majorFloor && o.version_added_collection && newerThan(o.version_added, majorFloor)) {
|
|
109
|
-
flags.push(`[added in ${o.version_added_collection} ${o.version_added}]`);
|
|
110
|
-
}
|
|
111
|
-
const desc = oneLine(o.description, descLen);
|
|
112
|
-
return `${pad}${name} (${type})${flags.length ? ` ${flags.join(" ")}` : ""}${desc ? ` - ${desc}` : ""}`;
|
|
113
|
-
}
|
|
114
|
-
function newerThan(v, floor) {
|
|
115
|
-
const a = String(v).split(".").map(Number);
|
|
116
|
-
const b = floor.split(".").map(Number);
|
|
117
|
-
for (let i = 0; i < 3; i++) {
|
|
118
|
-
if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0);
|
|
119
|
-
}
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
function renderOptions(options, depth, descLen, majorFloor) {
|
|
123
|
-
const lines = [];
|
|
124
|
-
const pad = " ".repeat(depth);
|
|
125
|
-
for (const name of Object.keys(options).sort()) {
|
|
126
|
-
const o = options[name];
|
|
127
|
-
lines.push(optionLine(name, o, pad, descLen, majorFloor));
|
|
128
|
-
const sub = subOptionsOf(o);
|
|
129
|
-
if (sub) lines.push(...renderOptions(sub, depth + 1, descLen, majorFloor));
|
|
130
|
-
}
|
|
131
|
-
return lines;
|
|
132
|
-
}
|
|
133
|
-
function renderModuleDoc(r) {
|
|
134
|
-
const d = r.doc;
|
|
135
|
-
const resolved = r.asked !== d.fqcn ? ` [resolved from '${r.asked}']` : "";
|
|
136
|
-
let head = `${d.fqcn} (${r.type}, ${r.source})${resolved}`;
|
|
137
|
-
if (d.deprecated) {
|
|
138
|
-
const dep = d.deprecated;
|
|
139
|
-
head += ` [DEPRECATED${dep.removed_in ? `: removed in ${dep.removed_in}` : ""}${dep.why ? `; ${oneLine(dep.why, 120)}` : ""}${dep.alternative ? `; ${oneLine(dep.alternative, 120)}` : ""}]`;
|
|
140
|
-
}
|
|
141
|
-
if (d.hasAction) head += " [has action plugin]";
|
|
142
|
-
if (d.shortDescription) head += ` - ${d.shortDescription}`;
|
|
143
|
-
const lines = [head];
|
|
144
|
-
const meta = [];
|
|
145
|
-
if (d.checkMode) meta.push(`check_mode: ${d.checkMode}`);
|
|
146
|
-
if (d.requirements.length) meta.push(`requirements: ${d.requirements.join("; ")}`);
|
|
147
|
-
if (meta.length) lines.push(meta.join(" | "));
|
|
148
|
-
const opts = d.options ?? {};
|
|
149
|
-
lines.push(`options (${Object.keys(opts).length}):`);
|
|
150
|
-
lines.push(...renderOptions(opts, 1, r.descriptionChars, r.majorFloor));
|
|
151
|
-
if (r.type === "module") {
|
|
152
|
-
lines.push(
|
|
153
|
-
"not in ansible-doc output: cross-option rules (mutually_exclusive, required_if, ...); see the module description and notes"
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
if (r.includeReturn && r.type === "module") {
|
|
157
|
-
const ret = Object.entries(d.returns ?? {});
|
|
158
|
-
if (ret.length === 0) {
|
|
159
|
-
lines.push("returns: (none documented)");
|
|
160
|
-
} else {
|
|
161
|
-
lines.push(`returns (${ret.length}):`);
|
|
162
|
-
for (const [k, v] of ret.sort(([a], [b]) => a < b ? -1 : 1)) {
|
|
163
|
-
const desc = oneLine(v?.description, r.descriptionChars);
|
|
164
|
-
lines.push(
|
|
165
|
-
` ${k} (${v?.type ?? "?"}${v?.returned ? `, ${oneLine(v.returned, 40)}` : ""})${desc ? ` - ${desc}` : ""}`
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (r.includeExamples && d.examples.trim()) {
|
|
171
|
-
lines.push("examples:");
|
|
172
|
-
lines.push(...d.examples.replace(/^\n+|\s+$/g, "").split("\n"));
|
|
173
|
-
}
|
|
174
|
-
return lines.join("\n");
|
|
175
|
-
}
|
|
176
|
-
function collectionRootOf(filename) {
|
|
177
|
-
const m = /^(.*\/ansible_collections\/[^/]+\/[^/]+)\//.exec(filename.replace(/\\/g, "/"));
|
|
178
|
-
return m ? m[1] : null;
|
|
179
|
-
}
|
|
180
|
-
function collectionsPathOf(filename) {
|
|
181
|
-
const m = /^(.*)\/ansible_collections\//.exec(filename.replace(/\\/g, "/"));
|
|
182
|
-
return m ? m[1] : null;
|
|
183
|
-
}
|
|
184
|
-
var PLUGIN_TYPES = [
|
|
185
|
-
"module",
|
|
186
|
-
"lookup",
|
|
187
|
-
"filter",
|
|
188
|
-
"test",
|
|
189
|
-
"callback",
|
|
190
|
-
"connection",
|
|
191
|
-
"inventory",
|
|
192
|
-
"become",
|
|
193
|
-
"cache",
|
|
194
|
-
"vars",
|
|
195
|
-
"strategy",
|
|
196
|
-
"shell",
|
|
197
|
-
"cliconf",
|
|
198
|
-
"httpapi",
|
|
199
|
-
"netconf",
|
|
200
|
-
"keyword",
|
|
201
|
-
"role"
|
|
202
|
-
];
|
|
203
|
-
function isPluginType(t) {
|
|
204
|
-
return PLUGIN_TYPES.includes(t);
|
|
205
|
-
}
|
|
206
|
-
var BAD_TYPE_MESSAGE = `type must be one of ${PLUGIN_TYPES.join(", ")}`;
|
|
207
|
-
|
|
208
11
|
// src/redact.ts
|
|
209
12
|
var VAULTED = "<vaulted>";
|
|
210
13
|
var REDACTED_VALUE = "(redacted: contains a secret value)";
|
|
@@ -362,7 +165,7 @@ var SHAPES = [
|
|
|
362
165
|
/LS0tLS1CRUdJTi[A-Za-z0-9+/=]{0,40}(UFJJVkFURSBLRVk|BSSVZBVEUgS0VZ|UklWQVRFIEtFW)/
|
|
363
166
|
];
|
|
364
167
|
var VAULT_TEXT = /^\s*\$ANSIBLE_VAULT;/;
|
|
365
|
-
var URL_USERINFO = /\b([a-z][a-z0-9+.-]*:\/\/)([^\s:@/]
|
|
168
|
+
var URL_USERINFO = /\b([a-z][a-z0-9+.-]*:\/\/)([^\s:@/]*):([^\s@/]+)@/gi;
|
|
366
169
|
function hasSecretShape(s) {
|
|
367
170
|
return SHAPES.some((re) => re.test(s));
|
|
368
171
|
}
|
|
@@ -490,11 +293,13 @@ var Redactor = class {
|
|
|
490
293
|
const url = maskUrlPasswords(v);
|
|
491
294
|
if (url !== null) this.counts.url++;
|
|
492
295
|
const inline = maskInlineCredentials(url ?? v);
|
|
493
|
-
if (inline !== null)
|
|
494
|
-
|
|
495
|
-
|
|
296
|
+
if (inline !== null) this.counts.shape++;
|
|
297
|
+
const masked = inline ?? url;
|
|
298
|
+
if (masked !== null) {
|
|
299
|
+
if (!this.matches(masked)) return masked;
|
|
300
|
+
this.counts.value++;
|
|
301
|
+
return new Hidden(REDACTED_VALUE);
|
|
496
302
|
}
|
|
497
|
-
if (url !== null) return url;
|
|
498
303
|
if (this.matches(v)) {
|
|
499
304
|
this.counts.value++;
|
|
500
305
|
return new Hidden(REDACTED_VALUE);
|
|
@@ -540,11 +345,212 @@ var Redactor = class {
|
|
|
540
345
|
return parts.length ? `redacted: ${parts.join(", ")}` : "";
|
|
541
346
|
}
|
|
542
347
|
};
|
|
348
|
+
function redactStandalone(value, key) {
|
|
349
|
+
const red = new Redactor();
|
|
350
|
+
red.learn(value, [key]);
|
|
351
|
+
return red.render(value, [key]);
|
|
352
|
+
}
|
|
543
353
|
function stringify(v) {
|
|
544
354
|
if (v instanceof Hidden) return v.text;
|
|
545
355
|
return JSON.stringify(v, (_k, x) => x instanceof Hidden ? x.text : x) ?? "null";
|
|
546
356
|
}
|
|
547
357
|
|
|
358
|
+
// src/ansibleDoc.ts
|
|
359
|
+
var asText = (d) => Array.isArray(d) ? d.map(String).join(" ") : typeof d === "string" ? d : d === void 0 || d === null ? "" : String(d);
|
|
360
|
+
function parseDocJson(text2) {
|
|
361
|
+
const out = /* @__PURE__ */ new Map();
|
|
362
|
+
const t = text2.trim();
|
|
363
|
+
if (!t) return out;
|
|
364
|
+
let data;
|
|
365
|
+
try {
|
|
366
|
+
data = JSON.parse(t);
|
|
367
|
+
} catch (e) {
|
|
368
|
+
throw new Error(`ansible-doc --json did not return JSON (${e instanceof Error ? e.message : String(e)}).`);
|
|
369
|
+
}
|
|
370
|
+
for (const [key, entry] of Object.entries(data ?? {})) {
|
|
371
|
+
const doc = entry?.doc;
|
|
372
|
+
if (!doc || typeof doc !== "object") continue;
|
|
373
|
+
out.set(key, {
|
|
374
|
+
key,
|
|
375
|
+
fqcn: String(doc.plugin_name ?? key),
|
|
376
|
+
collection: String(doc.collection ?? ""),
|
|
377
|
+
filename: String(doc.filename ?? ""),
|
|
378
|
+
hasAction: doc.has_action === true,
|
|
379
|
+
shortDescription: asText(doc.short_description),
|
|
380
|
+
description: asText(doc.description),
|
|
381
|
+
options: doc.options ?? {},
|
|
382
|
+
deprecated: doc.deprecated && typeof doc.deprecated === "object" ? doc.deprecated : void 0,
|
|
383
|
+
checkMode: doc.attributes?.check_mode?.support,
|
|
384
|
+
requirements: Array.isArray(doc.requirements) ? doc.requirements.map(String) : [],
|
|
385
|
+
returns: entry.return && typeof entry.return === "object" ? entry.return : null,
|
|
386
|
+
examples: typeof entry.examples === "string" ? entry.examples : "",
|
|
387
|
+
versionAdded: doc.version_added
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
return out;
|
|
391
|
+
}
|
|
392
|
+
var TOMBSTONE = /\[ERROR\]: (?:\w+ )?(\S+) Missing documentation \(or could not parse documentation\): (?:The '[^']+' \w+ has been removed\. )?(.*?) ?This feature was removed from collection '([^']+)' version ([^\s]+?)\.?$/;
|
|
393
|
+
function classifyDocStderr(stderr) {
|
|
394
|
+
const r = { missing: [], deprecations: [], tombstones: [], errors: [] };
|
|
395
|
+
for (const line of stderr.split(/\r?\n/)) {
|
|
396
|
+
let m = /^\[WARNING\]: (\S+) was not found$/.exec(line);
|
|
397
|
+
if (m) {
|
|
398
|
+
if (!r.missing.includes(m[1])) r.missing.push(m[1]);
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
m = /^\[DEPRECATION WARNING\]: (\S+) has been deprecated\. (.*)$/.exec(line);
|
|
402
|
+
if (m) {
|
|
403
|
+
r.deprecations.push({ name: m[1], text: m[2] });
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
m = TOMBSTONE.exec(line);
|
|
407
|
+
if (m) {
|
|
408
|
+
if (!r.tombstones.some((t) => t.name === m[1])) {
|
|
409
|
+
r.tombstones.push({ name: m[1], text: m[2].trim(), collection: m[3], version: m[4] });
|
|
410
|
+
}
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
if (line.startsWith("[ERROR]:")) r.errors.push(line.slice(9).trim());
|
|
414
|
+
}
|
|
415
|
+
return r;
|
|
416
|
+
}
|
|
417
|
+
function choicesOf(o) {
|
|
418
|
+
if (!o?.choices) return null;
|
|
419
|
+
return Array.isArray(o.choices) ? o.choices : Object.keys(o.choices);
|
|
420
|
+
}
|
|
421
|
+
function subOptionsOf(o) {
|
|
422
|
+
return o?.suboptions ?? o?.options ?? null;
|
|
423
|
+
}
|
|
424
|
+
var typeOf = (o) => o?.type ?? "str";
|
|
425
|
+
function findOption(options, name) {
|
|
426
|
+
if (Object.hasOwn(options, name)) return [name, options[name], void 0];
|
|
427
|
+
for (const [k, o] of Object.entries(options)) {
|
|
428
|
+
if (o.aliases?.includes(name)) return [k, o, name];
|
|
429
|
+
}
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
function oneLine(desc, max) {
|
|
433
|
+
let d = asText(desc).replace(/\s+/g, " ").trim();
|
|
434
|
+
if (max && d.length > max) d = `${d.slice(0, max)}...`;
|
|
435
|
+
return d;
|
|
436
|
+
}
|
|
437
|
+
function optionLine(name, o, pad, descLen, majorFloor) {
|
|
438
|
+
const t = typeOf(o);
|
|
439
|
+
const type = o.elements ? `${t} of ${o.elements}` : t;
|
|
440
|
+
const flags = [];
|
|
441
|
+
if (o.required) flags.push("[required]");
|
|
442
|
+
if (o.default !== void 0 && o.default !== null)
|
|
443
|
+
flags.push(o.no_log ? "[default: (no_log)]" : `[default: ${redactStandalone(o.default, name)}]`);
|
|
444
|
+
const ch = choicesOf(o);
|
|
445
|
+
if (ch) flags.push(`[choices: ${ch.map((c) => String(c)).join("|")}]`);
|
|
446
|
+
if (o.aliases?.length) flags.push(`[aliases: ${o.aliases.join(", ")}]`);
|
|
447
|
+
if (o.no_log) flags.push("[no_log]");
|
|
448
|
+
if (o.deprecated) {
|
|
449
|
+
const d = o.deprecated;
|
|
450
|
+
flags.push(
|
|
451
|
+
`[deprecated${d.removed_in ? `: removed in ${d.removed_in}` : ""}${d.alternative ? `, ${oneLine(d.alternative, 80)}` : ""}]`
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
if (o.version_added && majorFloor && o.version_added_collection && newerThan(o.version_added, majorFloor)) {
|
|
455
|
+
flags.push(`[added in ${o.version_added_collection} ${o.version_added}]`);
|
|
456
|
+
}
|
|
457
|
+
const desc = oneLine(o.description, descLen);
|
|
458
|
+
return `${pad}${name} (${type})${flags.length ? ` ${flags.join(" ")}` : ""}${desc ? ` - ${desc}` : ""}`;
|
|
459
|
+
}
|
|
460
|
+
function newerThan(v, floor) {
|
|
461
|
+
const a = String(v).split(".").map(Number);
|
|
462
|
+
const b = floor.split(".").map(Number);
|
|
463
|
+
for (let i = 0; i < 3; i++) {
|
|
464
|
+
if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0);
|
|
465
|
+
}
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
function renderOptions(options, depth, descLen, majorFloor) {
|
|
469
|
+
const lines = [];
|
|
470
|
+
const pad = " ".repeat(depth);
|
|
471
|
+
for (const name of Object.keys(options).sort()) {
|
|
472
|
+
const o = options[name];
|
|
473
|
+
lines.push(optionLine(name, o, pad, descLen, majorFloor));
|
|
474
|
+
const sub = subOptionsOf(o);
|
|
475
|
+
if (sub) lines.push(...renderOptions(sub, depth + 1, descLen, majorFloor));
|
|
476
|
+
}
|
|
477
|
+
return lines;
|
|
478
|
+
}
|
|
479
|
+
function renderModuleDoc(r) {
|
|
480
|
+
const d = r.doc;
|
|
481
|
+
const resolved = r.asked !== d.fqcn ? ` [resolved from '${r.asked}']` : "";
|
|
482
|
+
let head = `${d.fqcn} (${r.type}, ${r.source})${resolved}`;
|
|
483
|
+
if (d.deprecated) {
|
|
484
|
+
const dep = d.deprecated;
|
|
485
|
+
head += ` [DEPRECATED${dep.removed_in ? `: removed in ${dep.removed_in}` : ""}${dep.why ? `; ${oneLine(dep.why, 120)}` : ""}${dep.alternative ? `; ${oneLine(dep.alternative, 120)}` : ""}]`;
|
|
486
|
+
}
|
|
487
|
+
if (d.hasAction) head += " [has action plugin]";
|
|
488
|
+
if (d.shortDescription) head += ` - ${d.shortDescription}`;
|
|
489
|
+
const lines = [head];
|
|
490
|
+
const meta = [];
|
|
491
|
+
if (d.checkMode) meta.push(`check_mode: ${d.checkMode}`);
|
|
492
|
+
if (d.requirements.length) meta.push(`requirements: ${d.requirements.join("; ")}`);
|
|
493
|
+
if (meta.length) lines.push(meta.join(" | "));
|
|
494
|
+
const opts = d.options ?? {};
|
|
495
|
+
lines.push(`options (${Object.keys(opts).length}):`);
|
|
496
|
+
lines.push(...renderOptions(opts, 1, r.descriptionChars, r.majorFloor));
|
|
497
|
+
if (r.type === "module") {
|
|
498
|
+
lines.push(
|
|
499
|
+
"not in ansible-doc output: cross-option rules (mutually_exclusive, required_if, ...); see the module description and notes"
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
if (r.includeReturn && r.type === "module") {
|
|
503
|
+
const ret = Object.entries(d.returns ?? {});
|
|
504
|
+
if (ret.length === 0) {
|
|
505
|
+
lines.push("returns: (none documented)");
|
|
506
|
+
} else {
|
|
507
|
+
lines.push(`returns (${ret.length}):`);
|
|
508
|
+
for (const [k, v] of ret.sort(([a], [b]) => a < b ? -1 : 1)) {
|
|
509
|
+
const desc = oneLine(v?.description, r.descriptionChars);
|
|
510
|
+
lines.push(
|
|
511
|
+
` ${k} (${v?.type ?? "?"}${v?.returned ? `, ${oneLine(v.returned, 40)}` : ""})${desc ? ` - ${desc}` : ""}`
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (r.includeExamples && d.examples.trim()) {
|
|
517
|
+
lines.push("examples:");
|
|
518
|
+
lines.push(...d.examples.replace(/^\n+|\s+$/g, "").split("\n"));
|
|
519
|
+
}
|
|
520
|
+
return lines.join("\n");
|
|
521
|
+
}
|
|
522
|
+
function collectionRootOf(filename) {
|
|
523
|
+
const m = /^(.*\/ansible_collections\/[^/]+\/[^/]+)\//.exec(filename.replace(/\\/g, "/"));
|
|
524
|
+
return m ? m[1] : null;
|
|
525
|
+
}
|
|
526
|
+
function collectionsPathOf(filename) {
|
|
527
|
+
const m = /^(.*)\/ansible_collections\//.exec(filename.replace(/\\/g, "/"));
|
|
528
|
+
return m ? m[1] : null;
|
|
529
|
+
}
|
|
530
|
+
var PLUGIN_TYPES = [
|
|
531
|
+
"module",
|
|
532
|
+
"lookup",
|
|
533
|
+
"filter",
|
|
534
|
+
"test",
|
|
535
|
+
"callback",
|
|
536
|
+
"connection",
|
|
537
|
+
"inventory",
|
|
538
|
+
"become",
|
|
539
|
+
"cache",
|
|
540
|
+
"vars",
|
|
541
|
+
"strategy",
|
|
542
|
+
"shell",
|
|
543
|
+
"cliconf",
|
|
544
|
+
"httpapi",
|
|
545
|
+
"netconf",
|
|
546
|
+
"keyword",
|
|
547
|
+
"role"
|
|
548
|
+
];
|
|
549
|
+
function isPluginType(t) {
|
|
550
|
+
return PLUGIN_TYPES.includes(t);
|
|
551
|
+
}
|
|
552
|
+
var BAD_TYPE_MESSAGE = `type must be one of ${PLUGIN_TYPES.join(", ")}`;
|
|
553
|
+
|
|
548
554
|
// src/config.ts
|
|
549
555
|
function parseConfigDump(text2) {
|
|
550
556
|
let data;
|
|
@@ -959,24 +965,44 @@ var AnsibleRunner = class {
|
|
|
959
965
|
const d = this.distro();
|
|
960
966
|
return d ? `\\\\wsl.localhost\\${d}${p.replace(/\//g, "\\")}` : null;
|
|
961
967
|
}
|
|
962
|
-
/**
|
|
968
|
+
/**
|
|
969
|
+
* The Ansible side's environment (prefix mode; learned once per process). A
|
|
970
|
+
* spawn failure, a non-zero exit or an empty listing rejects and is not
|
|
971
|
+
* cached, so the next call asks again.
|
|
972
|
+
*/
|
|
963
973
|
sideEnv() {
|
|
964
974
|
if (!this.prefixed) return Promise.resolve(process.env);
|
|
965
|
-
this.sideEnvCache
|
|
966
|
-
const
|
|
967
|
-
|
|
968
|
-
const
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
975
|
+
if (!this.sideEnvCache) {
|
|
976
|
+
const p = this.raw("env", [], {}).then((r) => {
|
|
977
|
+
const out = {};
|
|
978
|
+
for (const line of r.stdout.split("\n")) {
|
|
979
|
+
const i = line.indexOf("=");
|
|
980
|
+
if (i > 0) out[line.slice(0, i)] = line.slice(i + 1);
|
|
981
|
+
}
|
|
982
|
+
if (r.code !== 0 || Object.keys(out).length === 0) {
|
|
983
|
+
throw new Error(
|
|
984
|
+
`could not read the Ansible side's environment (env exit ${r.code})${r.stderr.trim() ? `: ${r.stderr.trim().slice(0, 512)}` : ""}`
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
return out;
|
|
988
|
+
});
|
|
989
|
+
p.catch(() => {
|
|
990
|
+
this.sideEnvCache = null;
|
|
991
|
+
});
|
|
992
|
+
this.sideEnvCache = p;
|
|
993
|
+
}
|
|
973
994
|
return this.sideEnvCache;
|
|
974
995
|
}
|
|
975
996
|
/** Ansible-side cache root: ANSIBLE_MCP_REMOTE_CACHE, else $HOME/.cache/ansible-mcp (never /tmp, F24). */
|
|
976
997
|
async sideCacheRoot() {
|
|
977
998
|
if (!this.prefixed) return this.localCache;
|
|
978
999
|
if (this.remoteCacheOverride) return this.remoteCacheOverride;
|
|
979
|
-
const home = (await this.sideEnv()).HOME
|
|
1000
|
+
const home = (await this.sideEnv()).HOME;
|
|
1001
|
+
if (!home) {
|
|
1002
|
+
throw new Error(
|
|
1003
|
+
"HOME is not set on the Ansible side, so there is no cache dir (never /tmp, F24). Set ANSIBLE_MCP_REMOTE_CACHE to an Ansible-side directory."
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
980
1006
|
return posix.join(home, ".cache", "ansible-mcp");
|
|
981
1007
|
}
|
|
982
1008
|
/**
|
|
@@ -1124,10 +1150,17 @@ var AnsibleRunner = class {
|
|
|
1124
1150
|
const r = await this.raw("mv", ["-T", "--", from, to], {});
|
|
1125
1151
|
return r.code === 0;
|
|
1126
1152
|
}
|
|
1127
|
-
/**
|
|
1153
|
+
/**
|
|
1154
|
+
* Recursive delete of a `.tmp-*` dir, only under `guardRoot` (asserted): the
|
|
1155
|
+
* last segment must start with `.tmp-`, and no segment of either path may be
|
|
1156
|
+
* `.` or `..` (a plain prefix test would accept `<root>/../x/.tmp-y`).
|
|
1157
|
+
*/
|
|
1128
1158
|
async sideRemoveTemp(p, guardRoot) {
|
|
1129
|
-
const
|
|
1130
|
-
|
|
1159
|
+
const segs = (s) => s.replace(/\\/g, "/").replace(/\/+$/, "").split("/");
|
|
1160
|
+
const ps = segs(p);
|
|
1161
|
+
const rs = segs(guardRoot);
|
|
1162
|
+
const dotted = (x) => x.some((s) => s === "." || s === "..");
|
|
1163
|
+
if (dotted(ps) || dotted(rs) || ps.length <= rs.length || rs.some((s, i) => s !== ps[i]) || !ps.at(-1).startsWith(".tmp-")) {
|
|
1131
1164
|
throw new Error(`refusing to remove ${p}: not a temp dir under ${guardRoot}`);
|
|
1132
1165
|
}
|
|
1133
1166
|
if (!this.prefixed) {
|
|
@@ -1172,6 +1205,7 @@ var AnsibleContext = class {
|
|
|
1172
1205
|
configCache = /* @__PURE__ */ new Map();
|
|
1173
1206
|
versionCache = null;
|
|
1174
1207
|
fingerprints = /* @__PURE__ */ new Map();
|
|
1208
|
+
/** Per-name doc results; `deprecations` replays the batch's warnings naming that entry on a hit. */
|
|
1175
1209
|
docCache = /* @__PURE__ */ new Map();
|
|
1176
1210
|
listCache = /* @__PURE__ */ new Map();
|
|
1177
1211
|
/** Serializes ansible_upgrade_impact calls in this process. */
|
|
@@ -1329,6 +1363,9 @@ ${r.stderr.trim().slice(0, 2048)}`);
|
|
|
1329
1363
|
* tombstone retry (F2: one tombstone fails the whole batch, so it is recorded
|
|
1330
1364
|
* and the batch re-run without it). `collectionsPath` overrides
|
|
1331
1365
|
* ANSIBLE_COLLECTIONS_PATH (upgrade targets); those results are not cached.
|
|
1366
|
+
* A name starting with `-` is never a plugin name: it is reported missing and
|
|
1367
|
+
* never reaches argv (task keys are user data; `-M x` would be an option), and
|
|
1368
|
+
* the names follow `--` besides.
|
|
1332
1369
|
*/
|
|
1333
1370
|
async docs(p, names, opts = {}) {
|
|
1334
1371
|
const type = opts.type ?? "module";
|
|
@@ -1338,20 +1375,31 @@ ${r.stderr.trim().slice(0, 2048)}`);
|
|
|
1338
1375
|
const fp = cacheable ? await this.fingerprint(p) : "";
|
|
1339
1376
|
const todo = [];
|
|
1340
1377
|
for (const n of unique) {
|
|
1378
|
+
if (n.startsWith("-")) {
|
|
1379
|
+
result.missing.push(n);
|
|
1380
|
+
continue;
|
|
1381
|
+
}
|
|
1341
1382
|
const c = cacheable ? this.docCache.get(`${fp}|${type}|${n}`) : void 0;
|
|
1342
1383
|
if (!c) todo.push(n);
|
|
1343
|
-
else if ("kind" in c
|
|
1344
|
-
|
|
1345
|
-
|
|
1384
|
+
else if ("kind" in c) {
|
|
1385
|
+
if (c.kind === "doc" && c.doc) result.docs.set(n, c.doc);
|
|
1386
|
+
else result.missing.push(n);
|
|
1387
|
+
result.deprecations.push(...c.deprecations);
|
|
1388
|
+
} else result.tombstones.push(c);
|
|
1346
1389
|
}
|
|
1347
1390
|
const env = {};
|
|
1348
1391
|
if (opts.collectionsPath) env.ANSIBLE_COLLECTIONS_PATH = opts.collectionsPath;
|
|
1349
1392
|
for (let i = 0; i < todo.length; i += DOC_BATCH) {
|
|
1350
1393
|
let batch = todo.slice(i, i + DOC_BATCH);
|
|
1351
1394
|
for (let attempt = 0; batch.length > 0 && attempt <= batch.length; attempt++) {
|
|
1352
|
-
const r = await this.runSafe(
|
|
1353
|
-
|
|
1354
|
-
|
|
1395
|
+
const r = await this.runSafe(
|
|
1396
|
+
p,
|
|
1397
|
+
"ansible-doc",
|
|
1398
|
+
["--json", "-t", type, ...opts.extraArgs ?? [], "--", ...batch],
|
|
1399
|
+
{
|
|
1400
|
+
env
|
|
1401
|
+
}
|
|
1402
|
+
);
|
|
1355
1403
|
const st = classifyDocStderr(r.stderr);
|
|
1356
1404
|
if (r.code !== 0) {
|
|
1357
1405
|
const tomb = st.tombstones.filter((t) => batch.includes(t.name));
|
|
@@ -1369,12 +1417,14 @@ ${r.stderr.trim().slice(0, 2048)}`);
|
|
|
1369
1417
|
const docs = parseDocJson(r.stdout);
|
|
1370
1418
|
for (const n of batch) {
|
|
1371
1419
|
const d = docs.get(n);
|
|
1372
|
-
if (d)
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1420
|
+
if (d) result.docs.set(n, d);
|
|
1421
|
+
else result.missing.push(n);
|
|
1422
|
+
if (cacheable) {
|
|
1423
|
+
const deprecations = st.deprecations.filter((x) => x.name === n);
|
|
1424
|
+
this.docCache.set(
|
|
1425
|
+
`${fp}|${type}|${n}`,
|
|
1426
|
+
d ? { kind: "doc", doc: d, deprecations } : { kind: "missing", deprecations }
|
|
1427
|
+
);
|
|
1378
1428
|
}
|
|
1379
1429
|
}
|
|
1380
1430
|
result.deprecations.push(...st.deprecations);
|
|
@@ -1420,11 +1470,11 @@ import { z } from "zod";
|
|
|
1420
1470
|
|
|
1421
1471
|
// src/handlers.ts
|
|
1422
1472
|
import { readdirSync as readdirSync5, readFileSync as readFileSync4 } from "fs";
|
|
1423
|
-
import { dirname as dirname3, join as join6 } from "path";
|
|
1473
|
+
import { dirname as dirname3, join as join6, normalize } from "path";
|
|
1424
1474
|
|
|
1425
1475
|
// src/project.ts
|
|
1426
|
-
import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync2, statSync as statSync2 } from "fs";
|
|
1427
|
-
import { dirname, join as join2, posix as posix2 } from "path";
|
|
1476
|
+
import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync2, realpathSync, statSync as statSync2 } from "fs";
|
|
1477
|
+
import { dirname, isAbsolute, join as join2, posix as posix2 } from "path";
|
|
1428
1478
|
|
|
1429
1479
|
// src/yaml.ts
|
|
1430
1480
|
import {
|
|
@@ -1462,6 +1512,8 @@ var pyFalse = {
|
|
|
1462
1512
|
resolve: () => false
|
|
1463
1513
|
};
|
|
1464
1514
|
var NULL_SCALAR = (line) => ({ kind: "scalar", value: null, line, raw: "" });
|
|
1515
|
+
var MAX_ALIAS_EXPANSION = 1e5;
|
|
1516
|
+
var ALIAS_LIMIT_ERROR = "alias expansion limit exceeded";
|
|
1465
1517
|
function parseYaml(src) {
|
|
1466
1518
|
const lc = new LineCounter();
|
|
1467
1519
|
const docs = parseAllDocuments(src, {
|
|
@@ -1485,6 +1537,16 @@ function parseYaml(src) {
|
|
|
1485
1537
|
const line = (offset) => offset === void 0 ? 0 : lc.linePos(offset).line;
|
|
1486
1538
|
const convertedCache = /* @__PURE__ */ new WeakMap();
|
|
1487
1539
|
const inProgress = /* @__PURE__ */ new WeakSet();
|
|
1540
|
+
const sizes = /* @__PURE__ */ new WeakMap();
|
|
1541
|
+
let aliasBudget = MAX_ALIAS_EXPANSION;
|
|
1542
|
+
let aliasLimitHit = false;
|
|
1543
|
+
const sizeOf = (y) => {
|
|
1544
|
+
const known = sizes.get(y);
|
|
1545
|
+
if (known !== void 0) return known;
|
|
1546
|
+
const n = y.kind === "scalar" ? 1 : y.kind === "seq" ? y.items.reduce((a, i) => a + sizeOf(i), 1) : y.entries.reduce((a, e) => a + sizeOf(e.value), 1);
|
|
1547
|
+
sizes.set(y, n);
|
|
1548
|
+
return n;
|
|
1549
|
+
};
|
|
1488
1550
|
const mergeEntries = (node) => {
|
|
1489
1551
|
const anchors = isAlias(node) ? [node] : isSeq(node) ? node.items : [];
|
|
1490
1552
|
const out = [];
|
|
@@ -1496,10 +1558,23 @@ function parseYaml(src) {
|
|
|
1496
1558
|
}
|
|
1497
1559
|
return out;
|
|
1498
1560
|
};
|
|
1561
|
+
const aliasKey = (k, fallbackLine) => {
|
|
1562
|
+
const conv = convert(k, fallbackLine);
|
|
1563
|
+
return conv.kind === "scalar" && conv.value !== null && typeof conv.value !== "object" ? String(conv.value) : String(k);
|
|
1564
|
+
};
|
|
1499
1565
|
const convert = (node, fallbackLine) => {
|
|
1500
1566
|
if (node === null || node === void 0) return NULL_SCALAR(fallbackLine);
|
|
1501
1567
|
if (isAlias(node)) {
|
|
1502
|
-
|
|
1568
|
+
const target = node.resolve(docs[0]);
|
|
1569
|
+
const aliasLine = line(node.range?.[0]);
|
|
1570
|
+
if (!target || aliasLimitHit) return NULL_SCALAR(aliasLine);
|
|
1571
|
+
const out = convert(target, aliasLine);
|
|
1572
|
+
aliasBudget -= sizeOf(out);
|
|
1573
|
+
if (aliasBudget < 0) {
|
|
1574
|
+
aliasLimitHit = true;
|
|
1575
|
+
return NULL_SCALAR(aliasLine);
|
|
1576
|
+
}
|
|
1577
|
+
return out;
|
|
1503
1578
|
}
|
|
1504
1579
|
const n = node;
|
|
1505
1580
|
const cached = convertedCache.get(n);
|
|
@@ -1533,7 +1608,7 @@ function parseYaml(src) {
|
|
|
1533
1608
|
for (const e of mergeEntries(item.value)) merged.push(e);
|
|
1534
1609
|
continue;
|
|
1535
1610
|
}
|
|
1536
|
-
const keyText = isScalar(k) ? String(k.value) : k ? String(k) : "";
|
|
1611
|
+
const keyText = isScalar(k) ? String(k.value) : isAlias(k) ? aliasKey(k, start) : k ? String(k) : "";
|
|
1537
1612
|
const keyLine = line(k?.range?.[0]) || start;
|
|
1538
1613
|
if (seen.has(keyText)) duplicates.push({ key: keyText, line: keyLine });
|
|
1539
1614
|
seen.add(keyText);
|
|
@@ -1572,6 +1647,7 @@ function parseYaml(src) {
|
|
|
1572
1647
|
for (const e of d.errors) errors.push(e.message.split("\n")[0]);
|
|
1573
1648
|
if (i === 0) root = d.contents ? convert(d.contents, 1) : null;
|
|
1574
1649
|
}
|
|
1650
|
+
if (aliasLimitHit) errors.push(`${ALIAS_LIMIT_ERROR} (more than ${MAX_ALIAS_EXPANSION} nodes through aliases)`);
|
|
1575
1651
|
return { root, errors, duplicates };
|
|
1576
1652
|
}
|
|
1577
1653
|
function toJS(node) {
|
|
@@ -1679,6 +1755,38 @@ function isFreeForm(fqcnOrName) {
|
|
|
1679
1755
|
}
|
|
1680
1756
|
return FREE_FORM.has(parts[parts.length - 1]);
|
|
1681
1757
|
}
|
|
1758
|
+
var CHECK_RAW_MODULES = /* @__PURE__ */ new Set(["command", "raw", "script", "shell", "win_command", "win_shell"]);
|
|
1759
|
+
var CHECK_RAW_OPTIONS = /* @__PURE__ */ new Set([
|
|
1760
|
+
"creates",
|
|
1761
|
+
"removes",
|
|
1762
|
+
"chdir",
|
|
1763
|
+
"executable",
|
|
1764
|
+
"warn",
|
|
1765
|
+
"stdin",
|
|
1766
|
+
"stdin_add_newline",
|
|
1767
|
+
"strip_empty_ends"
|
|
1768
|
+
]);
|
|
1769
|
+
function isCheckRawAction(action) {
|
|
1770
|
+
const parts = action.split(".");
|
|
1771
|
+
if (parts.length === 1) return CHECK_RAW_MODULES.has(action);
|
|
1772
|
+
if (parts.length !== 3) return false;
|
|
1773
|
+
if (parts[0] === "ansible" && (parts[1] === "builtin" || parts[1] === "legacy"))
|
|
1774
|
+
return CHECK_RAW_MODULES.has(parts[2]);
|
|
1775
|
+
return parts[0] === "ansible" && parts[1] === "windows" && /^win_(command|shell)$/.test(parts[2]);
|
|
1776
|
+
}
|
|
1777
|
+
var IMPORT_PLAYBOOK_KEYS = [
|
|
1778
|
+
"import_playbook",
|
|
1779
|
+
"ansible.builtin.import_playbook",
|
|
1780
|
+
"ansible.legacy.import_playbook"
|
|
1781
|
+
];
|
|
1782
|
+
var isPlayKey = (k) => k === "hosts" || IMPORT_PLAYBOOK_KEYS.includes(k);
|
|
1783
|
+
function importPlaybookEntry(play) {
|
|
1784
|
+
if (play.kind !== "map") return void 0;
|
|
1785
|
+
for (let i = play.entries.length - 1; i >= 0; i--) {
|
|
1786
|
+
if (IMPORT_PLAYBOOK_KEYS.includes(play.entries[i].key)) return play.entries[i].value;
|
|
1787
|
+
}
|
|
1788
|
+
return void 0;
|
|
1789
|
+
}
|
|
1682
1790
|
var INCLUDE_TASKS = /* @__PURE__ */ new Set(["include_tasks", "import_tasks", "include"]);
|
|
1683
1791
|
var INCLUDE_ROLE = /* @__PURE__ */ new Set(["include_role", "import_role"]);
|
|
1684
1792
|
var builtinName = (a) => a.replace(/^ansible\.(builtin|legacy)\./, "");
|
|
@@ -1730,7 +1838,7 @@ function unquote(v) {
|
|
|
1730
1838
|
if (v.length >= 2 && (v[0] === '"' || v[0] === "'") && v[v.length - 1] === v[0]) return v.slice(1, -1);
|
|
1731
1839
|
return v;
|
|
1732
1840
|
}
|
|
1733
|
-
function parseKv(s) {
|
|
1841
|
+
function parseKv(s, checkRaw = false) {
|
|
1734
1842
|
const options = {};
|
|
1735
1843
|
const raw = [];
|
|
1736
1844
|
for (const tok of splitArgs(s)) {
|
|
@@ -1746,7 +1854,7 @@ function parseKv(s) {
|
|
|
1746
1854
|
continue;
|
|
1747
1855
|
}
|
|
1748
1856
|
const k = tok.slice(0, pos).trim();
|
|
1749
|
-
if (/["']/.test(k)) {
|
|
1857
|
+
if (/["']/.test(k) || checkRaw && !CHECK_RAW_OPTIONS.has(k)) {
|
|
1750
1858
|
raw.push(tok);
|
|
1751
1859
|
continue;
|
|
1752
1860
|
}
|
|
@@ -1802,7 +1910,7 @@ function extractTask(map, file, doc, extra = {}) {
|
|
|
1802
1910
|
if (v.kind === "scalar" && typeof v.value === "string") {
|
|
1803
1911
|
const [mod, ...rest] = splitArgs(v.value);
|
|
1804
1912
|
t.action = mod;
|
|
1805
|
-
const kv = parseKv(rest.join(" "));
|
|
1913
|
+
const kv = parseKv(rest.join(" "), !!mod && isCheckRawAction(mod));
|
|
1806
1914
|
t.form = "kv";
|
|
1807
1915
|
t.args = Object.entries(kv).map(([k, val]) => ({ name: k, line: v.line, value: val }));
|
|
1808
1916
|
} else if (v.kind === "map") {
|
|
@@ -1826,12 +1934,18 @@ function extractTask(map, file, doc, extra = {}) {
|
|
|
1826
1934
|
} else if (actionNode.kind === "scalar" && actionNode.value !== null && actionNode.value !== void 0) {
|
|
1827
1935
|
t.form = "kv";
|
|
1828
1936
|
const text2 = typeof actionNode.value === "string" ? actionNode.value : String(actionNode.value);
|
|
1829
|
-
t.args = Object.entries(parseKv(text2)).map(([k, val]) => ({
|
|
1937
|
+
t.args = Object.entries(parseKv(text2, isCheckRawAction(t.action))).map(([k, val]) => ({
|
|
1938
|
+
name: k,
|
|
1939
|
+
line: actionNode.line,
|
|
1940
|
+
value: val
|
|
1941
|
+
}));
|
|
1830
1942
|
}
|
|
1831
1943
|
}
|
|
1832
1944
|
const argsKw = get(map, "args");
|
|
1833
1945
|
if (argsKw?.kind === "map") {
|
|
1946
|
+
const own = new Set(t.args.map((a) => a.name));
|
|
1834
1947
|
for (const e of argsKw.entries) {
|
|
1948
|
+
if (own.has(e.key)) continue;
|
|
1835
1949
|
t.args = t.args.filter((a) => a.name !== e.key);
|
|
1836
1950
|
t.args.push(entryArg(e.key, e.keyLine, e.value));
|
|
1837
1951
|
}
|
|
@@ -1874,11 +1988,11 @@ function tasksOf(seq, file, doc, extra = {}) {
|
|
|
1874
1988
|
}
|
|
1875
1989
|
function isPlaybookRoot(root) {
|
|
1876
1990
|
if (root?.kind !== "seq" || root.items.length === 0) return false;
|
|
1877
|
-
return root.items.every(
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
);
|
|
1991
|
+
return root.items.every((i) => i.kind === "map" && i.entries.some((e) => isPlayKey(e.key)));
|
|
1992
|
+
}
|
|
1993
|
+
function isPlaybookLike(root) {
|
|
1994
|
+
if (root?.kind !== "seq") return false;
|
|
1995
|
+
return root.items.some((i) => i.kind === "map" && i.entries.some((e) => isPlayKey(e.key)));
|
|
1882
1996
|
}
|
|
1883
1997
|
var MAX_YAML_BYTES = 2 * 1024 * 1024;
|
|
1884
1998
|
var ProjectFiles = class {
|
|
@@ -1886,25 +2000,37 @@ var ProjectFiles = class {
|
|
|
1886
2000
|
this.dir = dir;
|
|
1887
2001
|
}
|
|
1888
2002
|
dir;
|
|
2003
|
+
/** Per path: the parsed doc (null when unread), and the file size (undefined when not a readable file). */
|
|
1889
2004
|
cache = /* @__PURE__ */ new Map();
|
|
2005
|
+
/** An absolute input is returned unchanged (a playbook outside dir); a relative one joins dir. */
|
|
1890
2006
|
abs(rel) {
|
|
1891
|
-
return join2(this.dir, rel);
|
|
2007
|
+
return isAbsolute(rel) ? rel : join2(this.dir, rel);
|
|
1892
2008
|
}
|
|
2009
|
+
/** Relative to dir when inside it (drive-letter / case-insensitive on Windows), else the forward-slashed path. */
|
|
1893
2010
|
rel(abs) {
|
|
1894
2011
|
const a = abs.replace(/\\/g, "/");
|
|
1895
2012
|
const b = this.dir.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
2013
|
+
const fold = (x) => process.platform === "win32" ? x.toLowerCase() : x;
|
|
2014
|
+
return fold(a).startsWith(fold(`${b}/`)) ? a.slice(b.length + 1) : a;
|
|
2015
|
+
}
|
|
2016
|
+
/** Parse a YAML file of at most `maxBytes` (default 2 MiB); null when missing, unreadable or larger. */
|
|
2017
|
+
read(abs, maxBytes = MAX_YAML_BYTES) {
|
|
2018
|
+
const hit = this.cache.get(abs);
|
|
2019
|
+
if (hit && (hit.size === void 0 || hit.size > maxBytes)) return null;
|
|
2020
|
+
if (hit?.doc) return hit.doc;
|
|
1900
2021
|
let doc = null;
|
|
2022
|
+
let size;
|
|
1901
2023
|
try {
|
|
1902
2024
|
const st = statSync2(abs);
|
|
1903
|
-
if (st.isFile()
|
|
2025
|
+
if (st.isFile()) {
|
|
2026
|
+
size = st.size;
|
|
2027
|
+
if (st.size <= maxBytes) doc = parseYaml(readFileSync2(abs, "utf8"));
|
|
2028
|
+
}
|
|
1904
2029
|
} catch {
|
|
1905
2030
|
doc = null;
|
|
2031
|
+
size = void 0;
|
|
1906
2032
|
}
|
|
1907
|
-
this.cache.set(abs, doc);
|
|
2033
|
+
this.cache.set(abs, { doc, size });
|
|
1908
2034
|
return doc;
|
|
1909
2035
|
}
|
|
1910
2036
|
};
|
|
@@ -2034,7 +2160,7 @@ function walkPlaybooks(files, playbooks, opts) {
|
|
|
2034
2160
|
const rel = files.rel(abs);
|
|
2035
2161
|
for (const play of root.items) {
|
|
2036
2162
|
if (play.kind !== "map") continue;
|
|
2037
|
-
const imp =
|
|
2163
|
+
const imp = importPlaybookEntry(play);
|
|
2038
2164
|
if (imp) {
|
|
2039
2165
|
const target = scalarString(imp);
|
|
2040
2166
|
if (target && !isTemplated(target)) {
|
|
@@ -2115,6 +2241,53 @@ function walkFiles(dir, depth, out, base = dir) {
|
|
|
2115
2241
|
}
|
|
2116
2242
|
}
|
|
2117
2243
|
}
|
|
2244
|
+
var TREE_SKIP_DIRS = /* @__PURE__ */ new Set([".cache", ".git", ".hg", ".svn", ".tox"]);
|
|
2245
|
+
var TREE_MAX_ENTRIES = 2e5;
|
|
2246
|
+
function yamlFilesUnder(dir, maxEntries = TREE_MAX_ENTRIES) {
|
|
2247
|
+
const files = [];
|
|
2248
|
+
const realSeen = /* @__PURE__ */ new Set();
|
|
2249
|
+
let entriesSeen = 0;
|
|
2250
|
+
let incomplete;
|
|
2251
|
+
const walk = (d) => {
|
|
2252
|
+
if (incomplete) return;
|
|
2253
|
+
try {
|
|
2254
|
+
const real = realpathSync(d);
|
|
2255
|
+
if (realSeen.has(real)) return;
|
|
2256
|
+
realSeen.add(real);
|
|
2257
|
+
} catch {
|
|
2258
|
+
incomplete = `could not be fully listed (${d})`;
|
|
2259
|
+
return;
|
|
2260
|
+
}
|
|
2261
|
+
let entries;
|
|
2262
|
+
try {
|
|
2263
|
+
entries = readdirSync(d, { withFileTypes: true });
|
|
2264
|
+
} catch {
|
|
2265
|
+
incomplete = `could not be fully listed (${d})`;
|
|
2266
|
+
return;
|
|
2267
|
+
}
|
|
2268
|
+
for (const e of entries.sort((x, y) => x.name < y.name ? -1 : x.name > y.name ? 1 : 0)) {
|
|
2269
|
+
if (++entriesSeen > maxEntries) {
|
|
2270
|
+
incomplete = `has more than ${maxEntries} entries to pre-scan`;
|
|
2271
|
+
return;
|
|
2272
|
+
}
|
|
2273
|
+
const p = join2(d, e.name);
|
|
2274
|
+
let isDirEntry = e.isDirectory();
|
|
2275
|
+
let isFileEntry = e.isFile();
|
|
2276
|
+
if (e.isSymbolicLink()) {
|
|
2277
|
+
isDirEntry = isDir(p);
|
|
2278
|
+
isFileEntry = isFile(p);
|
|
2279
|
+
}
|
|
2280
|
+
if (isDirEntry) {
|
|
2281
|
+
if (!TREE_SKIP_DIRS.has(e.name)) walk(p);
|
|
2282
|
+
} else if (isFileEntry && /\.ya?ml$/i.test(e.name)) {
|
|
2283
|
+
files.push(p);
|
|
2284
|
+
}
|
|
2285
|
+
if (incomplete) return;
|
|
2286
|
+
}
|
|
2287
|
+
};
|
|
2288
|
+
walk(dir);
|
|
2289
|
+
return incomplete ? { files, incomplete } : { files };
|
|
2290
|
+
}
|
|
2118
2291
|
function readCfgStatic(dir) {
|
|
2119
2292
|
const p = join2(dir, "ansible.cfg");
|
|
2120
2293
|
if (!isFile(p)) return {};
|
|
@@ -2304,7 +2477,7 @@ function checkValue(label, spec, v, line, node, out) {
|
|
|
2304
2477
|
}
|
|
2305
2478
|
const choices = choicesOf(spec);
|
|
2306
2479
|
const elements = type === "list" ? spec.elements ?? null : null;
|
|
2307
|
-
const items =
|
|
2480
|
+
const items = type === "list" && Array.isArray(v) ? v : [v];
|
|
2308
2481
|
if (choices && (type !== "list" || Array.isArray(v) || typeof v !== "object")) {
|
|
2309
2482
|
const list = type === "list" && typeof v === "string" ? v.split(",").map((s) => s.trim()) : items;
|
|
2310
2483
|
for (const item of list) {
|
|
@@ -2312,7 +2485,7 @@ function checkValue(label, spec, v, line, node, out) {
|
|
|
2312
2485
|
if (choices.some((c) => c === item || String(c) === String(item))) continue;
|
|
2313
2486
|
if (typeof item === "boolean" && raw && isYaml11BoolWord(raw)) {
|
|
2314
2487
|
out.values.push(
|
|
2315
|
-
`${where}: unquoted ${raw} is the boolean ${item} in YAML 1.1, not one of ${choices.map(String).join("|")}; quote it ("${raw}")`
|
|
2488
|
+
sensitive(label, spec, item) ? `${where}: an unquoted value is a boolean in YAML 1.1, not one of ${choices.map(String).join("|")}; quote it` : `${where}: unquoted ${raw} is the boolean ${item} in YAML 1.1, not one of ${choices.map(String).join("|")}; quote it ("${raw}")`
|
|
2316
2489
|
);
|
|
2317
2490
|
} else {
|
|
2318
2491
|
out.values.push(`${where}: ${show(item)} is not one of ${choices.map(String).join("|")}`);
|
|
@@ -2327,13 +2500,16 @@ function checkValue(label, spec, v, line, node, out) {
|
|
|
2327
2500
|
out.values.push(`${where}: expected ${type}, got ${err}${detail}`);
|
|
2328
2501
|
return;
|
|
2329
2502
|
}
|
|
2503
|
+
const hide = sensitive(label, spec, v);
|
|
2330
2504
|
if (type === "str" && typeof v === "boolean" && raw && isYaml11BoolWord(raw)) {
|
|
2331
2505
|
out.values.push(
|
|
2332
|
-
`${where}: unquoted ${raw} becomes the boolean ${v} in YAML 1.1 (Ansible passes the string '${v ? "True" : "False"}'); quote it ("${raw}")`
|
|
2506
|
+
hide ? `${where}: an unquoted value becomes a boolean in YAML 1.1; quote it` : `${where}: unquoted ${raw} becomes the boolean ${v} in YAML 1.1 (Ansible passes the string '${v ? "True" : "False"}'); quote it ("${raw}")`
|
|
2333
2507
|
);
|
|
2334
2508
|
}
|
|
2335
2509
|
if (type === "str" && typeof v === "number" && /^0[0-7]+$/.test(raw)) {
|
|
2336
|
-
out.values.push(
|
|
2510
|
+
out.values.push(
|
|
2511
|
+
hide ? `${where}: an unquoted value is an octal integer in YAML 1.1; quote it` : `${where}: unquoted ${raw} is the octal integer ${v} in YAML 1.1; quote it ("${raw}")`
|
|
2512
|
+
);
|
|
2337
2513
|
}
|
|
2338
2514
|
if (elements && Array.isArray(v)) {
|
|
2339
2515
|
const sub2 = subOptionsOf(spec);
|
|
@@ -3042,7 +3218,7 @@ function renderLint(version2, issues, stderr, maxLocations, profile) {
|
|
|
3042
3218
|
}
|
|
3043
3219
|
|
|
3044
3220
|
// src/playbook.ts
|
|
3045
|
-
import { readdirSync as readdirSync3 } from "fs";
|
|
3221
|
+
import { existsSync as existsSync4, readdirSync as readdirSync3 } from "fs";
|
|
3046
3222
|
import { dirname as dirname2, join as join4 } from "path";
|
|
3047
3223
|
var tagList = (s) => (s ?? "").replace(/^\[|\]$/g, "").split(",").map((x) => x.trim()).filter(Boolean);
|
|
3048
3224
|
function parseListOutput(text2) {
|
|
@@ -3121,35 +3297,51 @@ function firstSentence(text2) {
|
|
|
3121
3297
|
const i = text2.search(/\.\s+(?=[A-Z])/);
|
|
3122
3298
|
return (i > 0 ? text2.slice(0, i) : text2).replace(/\.$/, "");
|
|
3123
3299
|
}
|
|
3124
|
-
var LOOKUP_RE =
|
|
3300
|
+
var LOOKUP_RE = /\b(?:lookup|query|pipe)\b/;
|
|
3301
|
+
var Q_RE = /\bq\b/;
|
|
3302
|
+
function mentionsLookup(s) {
|
|
3303
|
+
if (LOOKUP_RE.test(s)) return true;
|
|
3304
|
+
const open = s.search(/\{[{%]/);
|
|
3305
|
+
return open >= 0 && Q_RE.test(s.slice(open));
|
|
3306
|
+
}
|
|
3307
|
+
var PRESCAN_MAX_BYTES = 32 * 1024 * 1024;
|
|
3125
3308
|
function prescanPlaybook(files, rel) {
|
|
3126
3309
|
const hits = [];
|
|
3127
3310
|
const seen = /* @__PURE__ */ new Set();
|
|
3128
3311
|
const visit = (abs) => {
|
|
3129
3312
|
if (seen.has(abs)) return;
|
|
3130
3313
|
seen.add(abs);
|
|
3131
|
-
const root = files.read(abs)?.root;
|
|
3132
|
-
if (root?.kind !== "seq") return;
|
|
3133
3314
|
const file = files.rel(abs);
|
|
3315
|
+
const doc = files.read(abs, PRESCAN_MAX_BYTES);
|
|
3316
|
+
if (!doc) {
|
|
3317
|
+
hits.push({ file, line: 0, play: "", field: "", unreadable: "could not be read" });
|
|
3318
|
+
return;
|
|
3319
|
+
}
|
|
3320
|
+
if (doc.errors.some((e) => e.startsWith(ALIAS_LIMIT_ERROR))) {
|
|
3321
|
+
hits.push({ file, line: 0, play: "", field: "", unreadable: `could not be fully parsed (${ALIAS_LIMIT_ERROR})` });
|
|
3322
|
+
return;
|
|
3323
|
+
}
|
|
3324
|
+
const root = doc.root;
|
|
3325
|
+
if (root?.kind !== "seq") return;
|
|
3134
3326
|
for (const play of root.items) {
|
|
3135
3327
|
if (play.kind !== "map") continue;
|
|
3136
3328
|
const nameNode = get(play, "name");
|
|
3137
3329
|
const label = nameNode?.kind === "scalar" && typeof nameNode.value === "string" ? nameNode.value : `#${play.line}`;
|
|
3138
3330
|
const check = (field, node) => {
|
|
3139
3331
|
for (const s of strings(node)) {
|
|
3140
|
-
if (
|
|
3332
|
+
if (mentionsLookup(s.value)) hits.push({ file, line: s.line, play: label, field });
|
|
3141
3333
|
}
|
|
3142
3334
|
};
|
|
3143
3335
|
check("name", nameNode);
|
|
3144
3336
|
check("hosts", get(play, "hosts"));
|
|
3145
3337
|
check("vars_files", get(play, "vars_files"));
|
|
3146
|
-
const imp =
|
|
3338
|
+
const imp = importPlaybookEntry(play);
|
|
3147
3339
|
if (imp) {
|
|
3148
3340
|
check("import_playbook", imp);
|
|
3149
3341
|
const target = imp.kind === "scalar" && typeof imp.value === "string" ? imp.value : null;
|
|
3150
3342
|
if (target && !isTemplated(target)) {
|
|
3151
3343
|
const p = join4(dirname2(abs), target);
|
|
3152
|
-
if (
|
|
3344
|
+
if (existsSync4(p)) visit(p);
|
|
3153
3345
|
}
|
|
3154
3346
|
}
|
|
3155
3347
|
}
|
|
@@ -3157,6 +3349,29 @@ function prescanPlaybook(files, rel) {
|
|
|
3157
3349
|
visit(files.abs(rel));
|
|
3158
3350
|
return hits;
|
|
3159
3351
|
}
|
|
3352
|
+
function prescanLintTargets(files, paths, maxEntries) {
|
|
3353
|
+
const hits = [];
|
|
3354
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3355
|
+
const scanFile = (abs) => {
|
|
3356
|
+
if (seen.has(abs)) return;
|
|
3357
|
+
seen.add(abs);
|
|
3358
|
+
const doc = files.read(abs, PRESCAN_MAX_BYTES);
|
|
3359
|
+
if (doc && !doc.errors.some((e) => e.startsWith(ALIAS_LIMIT_ERROR)) && !isPlaybookLike(doc.root)) return;
|
|
3360
|
+
hits.push(...prescanPlaybook(files, abs));
|
|
3361
|
+
};
|
|
3362
|
+
for (const p of paths) {
|
|
3363
|
+
if (isDir(p)) {
|
|
3364
|
+
const walk = yamlFilesUnder(p, maxEntries);
|
|
3365
|
+
if (walk.incomplete) {
|
|
3366
|
+
hits.push({ file: files.rel(p), line: 0, play: "", field: "", unreadable: walk.incomplete });
|
|
3367
|
+
}
|
|
3368
|
+
for (const abs of walk.files) scanFile(abs);
|
|
3369
|
+
} else if (existsSync4(p)) {
|
|
3370
|
+
scanFile(p);
|
|
3371
|
+
}
|
|
3372
|
+
}
|
|
3373
|
+
return hits;
|
|
3374
|
+
}
|
|
3160
3375
|
function strings(node) {
|
|
3161
3376
|
if (!node) return [];
|
|
3162
3377
|
if (node.kind === "scalar") return typeof node.value === "string" ? [{ value: node.value, line: node.line }] : [];
|
|
@@ -3165,7 +3380,7 @@ function strings(node) {
|
|
|
3165
3380
|
}
|
|
3166
3381
|
function prescanRefusal(hits) {
|
|
3167
3382
|
const lines = hits.map(
|
|
3168
|
-
(h) => `${h.file}:${h.line} play '${h.play}' has a lookup in '${h.field}'; Ansible would run it on this machine while parsing. Not run.`
|
|
3383
|
+
(h) => h.unreadable ? `${h.file} ${h.unreadable} for the lookup pre-scan; Ansible would parse it. Not run.` : `${h.file}:${h.line} play '${h.play}' has a lookup in '${h.field}'; Ansible would run it on this machine while parsing. Not run.`
|
|
3169
3384
|
);
|
|
3170
3385
|
lines.push("Set ANSIBLE_MCP_ALLOW_PLAY_LOOKUPS=1 to allow.");
|
|
3171
3386
|
return lines.join("\n");
|
|
@@ -3287,7 +3502,7 @@ function optionLines(opts, depth, descLen, defaults, warnings, ep, prefix) {
|
|
|
3287
3502
|
const flags = [];
|
|
3288
3503
|
if (o.required) flags.push("[required]");
|
|
3289
3504
|
if (o.default !== void 0 && o.default !== null)
|
|
3290
|
-
flags.push(o.no_log ? "[default: (no_log)]" : `[default: ${
|
|
3505
|
+
flags.push(o.no_log ? "[default: (no_log)]" : `[default: ${redactStandalone(o.default, name)}]`);
|
|
3291
3506
|
const ch = choicesOf(o);
|
|
3292
3507
|
if (ch) flags.push(`[choices: ${ch.map(String).join("|")}]`);
|
|
3293
3508
|
if (o.no_log) flags.push("[no_log]");
|
|
@@ -3327,13 +3542,16 @@ function renderRole(r) {
|
|
|
3327
3542
|
if (defaults) {
|
|
3328
3543
|
const noLog = /* @__PURE__ */ new Set();
|
|
3329
3544
|
const documented = /* @__PURE__ */ new Set();
|
|
3545
|
+
const red = new Redactor();
|
|
3330
3546
|
for (const e of Object.values(specs)) {
|
|
3331
3547
|
for (const [k, o] of Object.entries(e.options ?? {})) {
|
|
3332
3548
|
documented.add(k);
|
|
3333
3549
|
if (o.no_log) noLog.add(k);
|
|
3550
|
+
if (o.default === void 0 || o.default === null) continue;
|
|
3551
|
+
if (!o.no_log) red.learn(o.default, [k]);
|
|
3552
|
+
else if (typeof o.default === "string") red.addSecret(o.default);
|
|
3334
3553
|
}
|
|
3335
3554
|
}
|
|
3336
|
-
const red = new Redactor();
|
|
3337
3555
|
for (const [k, v] of Object.entries(defaults.values)) {
|
|
3338
3556
|
if (noLog.has(k)) {
|
|
3339
3557
|
if (typeof v === "string") red.addSecret(v);
|
|
@@ -3389,6 +3607,7 @@ function refuseDash(param, v) {
|
|
|
3389
3607
|
function assertRelative(ctx, p, rel, what) {
|
|
3390
3608
|
ctx.runner.assertLocal(rel);
|
|
3391
3609
|
refuseDash(what, rel);
|
|
3610
|
+
refuseDash(what, normalize(rel.trim()));
|
|
3392
3611
|
const abs = /^[A-Za-z]:[\\/]|^\//.test(rel) ? rel : join6(p.dir, rel);
|
|
3393
3612
|
ctx.runner.assertLocal(abs);
|
|
3394
3613
|
return abs;
|
|
@@ -3688,9 +3907,10 @@ async function roleInterface(ctx, x) {
|
|
|
3688
3907
|
let specs = null;
|
|
3689
3908
|
let source = "meta/argument_specs.yml";
|
|
3690
3909
|
if (ctx.runner.available()) {
|
|
3910
|
+
const base = roleDir.replace(/[\\/]+$/, "").split(/[\\/]/).pop();
|
|
3911
|
+
refuseDash("role", base);
|
|
3691
3912
|
try {
|
|
3692
3913
|
const sideParent = await ctx.runner.toSide(dirname3(roleDir));
|
|
3693
|
-
const base = roleDir.replace(/[\\/]+$/, "").split(/[\\/]/).pop();
|
|
3694
3914
|
const r = await ctx.runSafe(p, "ansible-doc", ["--json", "-t", "role", "-r", sideParent, base]);
|
|
3695
3915
|
if (r.code === 0) {
|
|
3696
3916
|
specs = roleSpecsFromDocJson(r.stdout, base)?.specs ?? null;
|
|
@@ -3757,11 +3977,6 @@ ${redactText(graph.stderr.trim()).slice(0, 2048)}`
|
|
|
3757
3977
|
for (const s of sources) bases.set(isDir(s) ? s : dirname3(s), "");
|
|
3758
3978
|
bases.set(p.dir, "");
|
|
3759
3979
|
const files = new ProjectFiles(p.dir);
|
|
3760
|
-
const fb = renderVarsFilesFallback(
|
|
3761
|
-
[...bases.keys()].map((b) => ({ base: b, label: files.rel(b) })),
|
|
3762
|
-
(abs) => files.rel(abs),
|
|
3763
|
-
red
|
|
3764
|
-
);
|
|
3765
3980
|
const env = { ANSIBLE_VARS_ENABLED: "none" };
|
|
3766
3981
|
const r = await ctx.runSafe(
|
|
3767
3982
|
p,
|
|
@@ -3771,23 +3986,32 @@ ${redactText(graph.stderr.trim()).slice(0, 2048)}`
|
|
|
3771
3986
|
env
|
|
3772
3987
|
}
|
|
3773
3988
|
);
|
|
3774
|
-
|
|
3775
|
-
`degraded: group_vars/host_vars merged by Ansible are unavailable because ${fb.vaulted.join(", ") || "a vars file"} ${fb.vaulted.length === 1 ? "is a whole-file vault" : "are whole-file vaults"} (ansible-mcp never supplies vault secrets); showing per-file contents instead, without precedence.`
|
|
3776
|
-
];
|
|
3989
|
+
let hv = null;
|
|
3777
3990
|
if (r.code === 0) {
|
|
3778
3991
|
try {
|
|
3779
3992
|
const data = JSON.parse(r.stdout);
|
|
3780
|
-
|
|
3993
|
+
hv = host ? { [host]: data } : data?._meta?.hostvars ?? {};
|
|
3781
3994
|
learnAll(red, hv);
|
|
3782
|
-
out.push("inventory-file vars only:");
|
|
3783
|
-
for (const [h, vars] of Object.entries(hv)) {
|
|
3784
|
-
if (varsMode === "names") out.push(` ${h}: ${Object.keys(vars).sort().join(" ") || "(none)"}`);
|
|
3785
|
-
else {
|
|
3786
|
-
out.push(` ${h}:`);
|
|
3787
|
-
out.push(...renderHostVars(vars, red, " "));
|
|
3788
|
-
}
|
|
3789
|
-
}
|
|
3790
3995
|
} catch {
|
|
3996
|
+
hv = null;
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
const fb = renderVarsFilesFallback(
|
|
4000
|
+
[...bases.keys()].map((b) => ({ base: b, label: files.rel(b) })),
|
|
4001
|
+
(abs) => files.rel(abs),
|
|
4002
|
+
red
|
|
4003
|
+
);
|
|
4004
|
+
const out = [
|
|
4005
|
+
`degraded: group_vars/host_vars merged by Ansible are unavailable because ${fb.vaulted.join(", ") || "a vars file"} ${fb.vaulted.length === 1 ? "is a whole-file vault" : "are whole-file vaults"} (ansible-mcp never supplies vault secrets); showing per-file contents instead, without precedence.`
|
|
4006
|
+
];
|
|
4007
|
+
if (hv) {
|
|
4008
|
+
out.push("inventory-file vars only:");
|
|
4009
|
+
for (const [h, vars] of Object.entries(hv)) {
|
|
4010
|
+
if (varsMode === "names") out.push(` ${h}: ${Object.keys(vars).sort().join(" ") || "(none)"}`);
|
|
4011
|
+
else {
|
|
4012
|
+
out.push(` ${h}:`);
|
|
4013
|
+
out.push(...renderHostVars(vars, red, " "));
|
|
4014
|
+
}
|
|
3791
4015
|
}
|
|
3792
4016
|
}
|
|
3793
4017
|
out.push("group_vars / host_vars files:");
|
|
@@ -4025,15 +4249,24 @@ async function lintSummary(ctx, x) {
|
|
|
4025
4249
|
if (x.profile && !PROFILES.includes(x.profile)) return `profile must be one of ${PROFILES.join(", ")}`;
|
|
4026
4250
|
const p = await ctx.project(x.dir);
|
|
4027
4251
|
const files = new ProjectFiles(p.dir);
|
|
4028
|
-
const
|
|
4029
|
-
|
|
4030
|
-
return files.rel(abs);
|
|
4031
|
-
});
|
|
4032
|
-
const playbooks = targets.length ? targets.filter((t) => isPlaybookRoot(files.read(join6(p.dir, t))?.root ?? null)) : detectProject(p.dir).playbooks.map((pb) => pb.rel);
|
|
4033
|
-
const hits = playbooks.flatMap((pb) => prescanPlaybook(files, pb));
|
|
4252
|
+
const targetAbs = (x.paths ?? []).map((rel) => assertRelative(ctx, p, rel, "paths"));
|
|
4253
|
+
const hits = prescanLintTargets(files, targetAbs.length ? targetAbs : [p.dir]);
|
|
4034
4254
|
if (hits.length && !ctx.allowPlayLookups) return prescanRefusal(hits);
|
|
4035
4255
|
ctx.runner.assertAvailable();
|
|
4036
|
-
const
|
|
4256
|
+
const targets = [];
|
|
4257
|
+
for (const a of targetAbs) {
|
|
4258
|
+
const rel = files.rel(a);
|
|
4259
|
+
const target = rel === a.replace(/\\/g, "/") ? await ctx.runner.toSide(a) : rel;
|
|
4260
|
+
refuseDash("paths", target);
|
|
4261
|
+
targets.push(target);
|
|
4262
|
+
}
|
|
4263
|
+
const args = [
|
|
4264
|
+
"--offline",
|
|
4265
|
+
"-f",
|
|
4266
|
+
"codeclimate",
|
|
4267
|
+
...x.profile ? ["--profile", x.profile] : [],
|
|
4268
|
+
...targets.length ? ["--", ...targets] : []
|
|
4269
|
+
];
|
|
4037
4270
|
const [r, v] = await Promise.all([
|
|
4038
4271
|
ctx.runSafe(p, "ansible-lint", args),
|
|
4039
4272
|
ctx.quietEnv().then((env) => ctx.runner.run("ansible-lint", ["--version", "--offline"], { env })).catch(() => null)
|
|
@@ -4068,7 +4301,18 @@ function routingFor(rt, type, fqcn, collection) {
|
|
|
4068
4301
|
const short = fqcn.startsWith(`${collection}.`) ? fqcn.slice(collection.length + 1) : fqcn;
|
|
4069
4302
|
return t[short] ?? t[fqcn];
|
|
4070
4303
|
}
|
|
4071
|
-
|
|
4304
|
+
function fmtDefault(v, name, noLog) {
|
|
4305
|
+
if (noLog) return NO_LOG;
|
|
4306
|
+
const r = redactStandalone(v ?? null, name);
|
|
4307
|
+
if (r.startsWith('"')) {
|
|
4308
|
+
try {
|
|
4309
|
+
const s = JSON.parse(r);
|
|
4310
|
+
if (typeof s === "string") return `'${s}'`;
|
|
4311
|
+
} catch {
|
|
4312
|
+
}
|
|
4313
|
+
}
|
|
4314
|
+
return r;
|
|
4315
|
+
}
|
|
4072
4316
|
var fmtChoiceValue = (v) => typeof v === "string" ? v : JSON.stringify(v);
|
|
4073
4317
|
function sensitive2(label, spec, v) {
|
|
4074
4318
|
return spec.no_log === true || isSecretKey(label) || typeof v === "string" && hasSecretShape(v);
|
|
@@ -4150,7 +4394,12 @@ function diffOptions(inst, targ, args, prefix, push) {
|
|
|
4150
4394
|
const dI = specI.default ?? null;
|
|
4151
4395
|
const dT = specT.default ?? null;
|
|
4152
4396
|
if (JSON.stringify(dI) !== JSON.stringify(dT)) {
|
|
4153
|
-
|
|
4397
|
+
const noLog = specI.no_log === true || specT.no_log === true;
|
|
4398
|
+
push(
|
|
4399
|
+
"BEHAVIOR CHANGE",
|
|
4400
|
+
`${prefix}${name} not set; default ${fmtDefault(dI, name, noLog)} -> ${fmtDefault(dT, name, noLog)}`,
|
|
4401
|
+
7
|
|
4402
|
+
);
|
|
4154
4403
|
}
|
|
4155
4404
|
}
|
|
4156
4405
|
}
|
|
@@ -4210,7 +4459,7 @@ function renderUpgrade(r) {
|
|
|
4210
4459
|
lines.push(
|
|
4211
4460
|
`upgrade ${r.collection} ${r.installedVersion} -> ${r.targetVersion} (${bumpKind(r.installedVersion, r.targetVersion)}${down}) for ${r.dirLabel}`
|
|
4212
4461
|
);
|
|
4213
|
-
const req = r.requiresAnsible ? `requires_ansible '${r.requiresAnsible}' ${r.requiresOk ? "ok" : "NOT satisfied"} (ansible-core ${r.core})
|
|
4462
|
+
const req = !r.requiresAnsible ? "requires_ansible not declared" : r.requiresOk === void 0 ? `requires_ansible '${r.requiresAnsible}' could not evaluate (${r.requiresError ?? "unparseable"}; ansible-core ${r.core})` : `requires_ansible '${r.requiresAnsible}' ${r.requiresOk ? "ok" : "NOT satisfied"} (ansible-core ${r.core})`;
|
|
4214
4463
|
lines.push(
|
|
4215
4464
|
`target: ${req}; dependencies: ${r.dependencies.length ? r.dependencies.join(", ") : "none"}; ${r.cacheNote}`
|
|
4216
4465
|
);
|
|
@@ -4266,6 +4515,8 @@ function renderUpgrade(r) {
|
|
|
4266
4515
|
else verdict = "NO IMPACT on used modules";
|
|
4267
4516
|
if (r.requiresAnsible && r.requiresOk === false) {
|
|
4268
4517
|
verdict = `BLOCKED (requires_ansible '${r.requiresAnsible}' excludes ansible-core ${r.core})${verdict.startsWith("BREAKING") ? `; also ${verdict}` : ""}`;
|
|
4518
|
+
} else if (r.requiresAnsible && r.requiresOk === void 0) {
|
|
4519
|
+
verdict += "; requires_ansible not checked";
|
|
4269
4520
|
}
|
|
4270
4521
|
lines.push(`verdict: ${verdict}`);
|
|
4271
4522
|
return lines.join("\n");
|
|
@@ -4354,6 +4605,7 @@ async function ensureTarget(ctx, p, collection, version2) {
|
|
|
4354
4605
|
if (hit && hit.collection_info?.version === version2) return { dir: target, downloaded: false, manifest: hit };
|
|
4355
4606
|
await ctx.runner.sideMkdirp(base);
|
|
4356
4607
|
const tmp = ctx.runner.sideJoin(base, `.tmp-${version2}-${randomBytes2(4).toString("hex")}`);
|
|
4608
|
+
let stale;
|
|
4357
4609
|
try {
|
|
4358
4610
|
const r = await ctx.runSafe(
|
|
4359
4611
|
p,
|
|
@@ -4371,16 +4623,22 @@ async function ensureTarget(ctx, p, collection, version2) {
|
|
|
4371
4623
|
if (!m || m.collection_info?.version !== version2) {
|
|
4372
4624
|
throw new Error(`ansible-galaxy installed ${collection} but MANIFEST.json does not say ${version2}.`);
|
|
4373
4625
|
}
|
|
4374
|
-
if (
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4626
|
+
if (await ctx.runner.sideRename(tmp, target)) return { dir: target, downloaded: true, manifest: m };
|
|
4627
|
+
const winner = await readManifest(ctx, target, collection);
|
|
4628
|
+
if (winner?.collection_info?.version === version2) return { dir: target, downloaded: true, manifest: winner };
|
|
4629
|
+
const aside = ctx.runner.sideJoin(base, `.tmp-stale-${randomBytes2(4).toString("hex")}`);
|
|
4630
|
+
if (await ctx.runner.sideRename(target, aside)) stale = aside;
|
|
4631
|
+
if (!stale || !await ctx.runner.sideRename(tmp, target)) {
|
|
4632
|
+
throw new Error(
|
|
4633
|
+
`could not move the downloaded ${collection} ${version2} into the cache at ${target} (it holds ${winner ? `a tree that says ${winner.collection_info?.version ?? "no version"}` : "no MANIFEST.json"}); remove that directory and retry.`
|
|
4634
|
+
);
|
|
4379
4635
|
}
|
|
4380
4636
|
return { dir: target, downloaded: true, manifest: m };
|
|
4381
4637
|
} finally {
|
|
4382
4638
|
await ctx.runner.sideRemoveTemp(tmp, root).catch(() => {
|
|
4383
4639
|
});
|
|
4640
|
+
if (stale) await ctx.runner.sideRemoveTemp(stale, root).catch(() => {
|
|
4641
|
+
});
|
|
4384
4642
|
}
|
|
4385
4643
|
}
|
|
4386
4644
|
function sweepStaleTempDirs(cacheDir, now = Date.now()) {
|
|
@@ -4436,7 +4694,7 @@ async function runUpgrade(ctx, x) {
|
|
|
4436
4694
|
if (listRes.code !== 0)
|
|
4437
4695
|
throw new Error(
|
|
4438
4696
|
`ansible-galaxy collection list failed (exit ${listRes.code}):
|
|
4439
|
-
${listRes.stderr.trim().slice(0, 2048)}`
|
|
4697
|
+
${redactText(listRes.stderr.trim()).slice(0, 2048)}`
|
|
4440
4698
|
);
|
|
4441
4699
|
const installedAll = byCollection(parseCollectionList(listRes.stdout), collectionsPaths);
|
|
4442
4700
|
const eff = installedAll.get(collection)?.[0];
|
|
@@ -4559,11 +4817,13 @@ ${listRes.stderr.trim().slice(0, 2048)}`
|
|
|
4559
4817
|
}
|
|
4560
4818
|
);
|
|
4561
4819
|
let requiresOk;
|
|
4820
|
+
let requiresError;
|
|
4562
4821
|
if (targetRuntime.requiresAnsible) {
|
|
4563
4822
|
try {
|
|
4564
4823
|
requiresOk = satisfies(ver.core.replace(/[^\d.].*$/, ""), targetRuntime.requiresAnsible);
|
|
4565
|
-
} catch {
|
|
4824
|
+
} catch (e) {
|
|
4566
4825
|
requiresOk = void 0;
|
|
4826
|
+
requiresError = e instanceof Error ? e.message : String(e);
|
|
4567
4827
|
}
|
|
4568
4828
|
}
|
|
4569
4829
|
const reqFiles = det.requirements.map((f) => {
|
|
@@ -4610,7 +4870,7 @@ ${listRes.stderr.trim().slice(0, 2048)}`
|
|
|
4610
4870
|
targetVersion: version2,
|
|
4611
4871
|
dirLabel: p.dir,
|
|
4612
4872
|
core: ver.core,
|
|
4613
|
-
...targetRuntime.requiresAnsible ? { requiresAnsible: targetRuntime.requiresAnsible, requiresOk } : {},
|
|
4873
|
+
...targetRuntime.requiresAnsible ? { requiresAnsible: targetRuntime.requiresAnsible, requiresOk, ...requiresError ? { requiresError } : {} } : {},
|
|
4614
4874
|
dependencies: deps,
|
|
4615
4875
|
cacheNote,
|
|
4616
4876
|
constraints,
|
|
@@ -4899,6 +5159,7 @@ async function startServer() {
|
|
|
4899
5159
|
await server.connect(transport);
|
|
4900
5160
|
}
|
|
4901
5161
|
export {
|
|
5162
|
+
ALIAS_LIMIT_ERROR,
|
|
4902
5163
|
AnsibleContext,
|
|
4903
5164
|
AnsibleRunner,
|
|
4904
5165
|
BAD_TYPE_MESSAGE,
|
|
@@ -4909,6 +5170,7 @@ export {
|
|
|
4909
5170
|
DRVFS_NOTE,
|
|
4910
5171
|
EXACT_VERSION_RE,
|
|
4911
5172
|
GALAXY_REDACTED,
|
|
5173
|
+
IMPORT_PLAYBOOK_KEYS,
|
|
4912
5174
|
INSTRUCTIONS,
|
|
4913
5175
|
MAX_TIMEOUT_MS,
|
|
4914
5176
|
NATIVE_WINDOWS_MESSAGE,
|
|
@@ -4961,10 +5223,13 @@ export {
|
|
|
4961
5223
|
groupsOf,
|
|
4962
5224
|
hasSecretShape,
|
|
4963
5225
|
hostMissing,
|
|
5226
|
+
importPlaybookEntry,
|
|
5227
|
+
isCheckRawAction,
|
|
4964
5228
|
isDir,
|
|
4965
5229
|
isFile,
|
|
4966
5230
|
isFreeForm,
|
|
4967
5231
|
isPlainTemplateRef,
|
|
5232
|
+
isPlaybookLike,
|
|
4968
5233
|
isPlaybookRoot,
|
|
4969
5234
|
isPluginType,
|
|
4970
5235
|
isSecretKey,
|
|
@@ -4982,6 +5247,7 @@ export {
|
|
|
4982
5247
|
maskInlineCredentials,
|
|
4983
5248
|
maskUrlPasswords,
|
|
4984
5249
|
maskedSecretValues,
|
|
5250
|
+
mentionsLookup,
|
|
4985
5251
|
missingBinaryPath,
|
|
4986
5252
|
mountRootFromWslpath,
|
|
4987
5253
|
nodeSpawner,
|
|
@@ -5004,11 +5270,13 @@ export {
|
|
|
5004
5270
|
parseWslUnc,
|
|
5005
5271
|
parseYaml,
|
|
5006
5272
|
prefixDistro,
|
|
5273
|
+
prescanLintTargets,
|
|
5007
5274
|
prescanPlaybook,
|
|
5008
5275
|
prescanRefusal,
|
|
5009
5276
|
readCfgStatic,
|
|
5010
5277
|
readDefaults,
|
|
5011
5278
|
readExecConfig,
|
|
5279
|
+
redactStandalone,
|
|
5012
5280
|
redactText,
|
|
5013
5281
|
relativeTo,
|
|
5014
5282
|
renderChecks,
|
|
@@ -5055,5 +5323,6 @@ export {
|
|
|
5055
5323
|
walkPlaybooks,
|
|
5056
5324
|
winToWsl,
|
|
5057
5325
|
wslToWin,
|
|
5058
|
-
yaml11Choices
|
|
5326
|
+
yaml11Choices,
|
|
5327
|
+
yamlFilesUnder
|
|
5059
5328
|
};
|