@yawlabs/ansible-mcp 0.1.0 → 0.1.2
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/README.md +1 -1
- package/dist/context.d.ts +4 -0
- package/dist/exec.d.ts +10 -2
- package/dist/index.js +566 -300
- 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 +576 -301
- package/dist/upgrade.d.ts +3 -0
- package/dist/yaml.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10,203 +10,6 @@ import { createHash } from "crypto";
|
|
|
10
10
|
import { existsSync as existsSync2, statSync } from "fs";
|
|
11
11
|
import { resolve } from "path";
|
|
12
12
|
|
|
13
|
-
// src/ansibleDoc.ts
|
|
14
|
-
var asText = (d) => Array.isArray(d) ? d.map(String).join(" ") : typeof d === "string" ? d : d === void 0 || d === null ? "" : String(d);
|
|
15
|
-
function parseDocJson(text2) {
|
|
16
|
-
const out = /* @__PURE__ */ new Map();
|
|
17
|
-
const t = text2.trim();
|
|
18
|
-
if (!t) return out;
|
|
19
|
-
let data;
|
|
20
|
-
try {
|
|
21
|
-
data = JSON.parse(t);
|
|
22
|
-
} catch (e) {
|
|
23
|
-
throw new Error(`ansible-doc --json did not return JSON (${e instanceof Error ? e.message : String(e)}).`);
|
|
24
|
-
}
|
|
25
|
-
for (const [key, entry] of Object.entries(data ?? {})) {
|
|
26
|
-
const doc = entry?.doc;
|
|
27
|
-
if (!doc || typeof doc !== "object") continue;
|
|
28
|
-
out.set(key, {
|
|
29
|
-
key,
|
|
30
|
-
fqcn: String(doc.plugin_name ?? key),
|
|
31
|
-
collection: String(doc.collection ?? ""),
|
|
32
|
-
filename: String(doc.filename ?? ""),
|
|
33
|
-
hasAction: doc.has_action === true,
|
|
34
|
-
shortDescription: asText(doc.short_description),
|
|
35
|
-
description: asText(doc.description),
|
|
36
|
-
options: doc.options ?? {},
|
|
37
|
-
deprecated: doc.deprecated && typeof doc.deprecated === "object" ? doc.deprecated : void 0,
|
|
38
|
-
checkMode: doc.attributes?.check_mode?.support,
|
|
39
|
-
requirements: Array.isArray(doc.requirements) ? doc.requirements.map(String) : [],
|
|
40
|
-
returns: entry.return && typeof entry.return === "object" ? entry.return : null,
|
|
41
|
-
examples: typeof entry.examples === "string" ? entry.examples : "",
|
|
42
|
-
versionAdded: doc.version_added
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return out;
|
|
46
|
-
}
|
|
47
|
-
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]+?)\.?$/;
|
|
48
|
-
function classifyDocStderr(stderr) {
|
|
49
|
-
const r = { missing: [], deprecations: [], tombstones: [], errors: [] };
|
|
50
|
-
for (const line of stderr.split(/\r?\n/)) {
|
|
51
|
-
let m = /^\[WARNING\]: (\S+) was not found$/.exec(line);
|
|
52
|
-
if (m) {
|
|
53
|
-
if (!r.missing.includes(m[1])) r.missing.push(m[1]);
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
m = /^\[DEPRECATION WARNING\]: (\S+) has been deprecated\. (.*)$/.exec(line);
|
|
57
|
-
if (m) {
|
|
58
|
-
r.deprecations.push({ name: m[1], text: m[2] });
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
m = TOMBSTONE.exec(line);
|
|
62
|
-
if (m) {
|
|
63
|
-
if (!r.tombstones.some((t) => t.name === m[1])) {
|
|
64
|
-
r.tombstones.push({ name: m[1], text: m[2].trim(), collection: m[3], version: m[4] });
|
|
65
|
-
}
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
if (line.startsWith("[ERROR]:")) r.errors.push(line.slice(9).trim());
|
|
69
|
-
}
|
|
70
|
-
return r;
|
|
71
|
-
}
|
|
72
|
-
function choicesOf(o) {
|
|
73
|
-
if (!o?.choices) return null;
|
|
74
|
-
return Array.isArray(o.choices) ? o.choices : Object.keys(o.choices);
|
|
75
|
-
}
|
|
76
|
-
function subOptionsOf(o) {
|
|
77
|
-
return o?.suboptions ?? o?.options ?? null;
|
|
78
|
-
}
|
|
79
|
-
var typeOf = (o) => o?.type ?? "str";
|
|
80
|
-
function findOption(options, name) {
|
|
81
|
-
if (Object.hasOwn(options, name)) return [name, options[name], void 0];
|
|
82
|
-
for (const [k, o] of Object.entries(options)) {
|
|
83
|
-
if (o.aliases?.includes(name)) return [k, o, name];
|
|
84
|
-
}
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
function oneLine(desc, max) {
|
|
88
|
-
let d = asText(desc).replace(/\s+/g, " ").trim();
|
|
89
|
-
if (max && d.length > max) d = `${d.slice(0, max)}...`;
|
|
90
|
-
return d;
|
|
91
|
-
}
|
|
92
|
-
var fmtDefault = (v) => JSON.stringify(v);
|
|
93
|
-
function optionLine(name, o, pad, descLen, majorFloor) {
|
|
94
|
-
const t = typeOf(o);
|
|
95
|
-
const type = o.elements ? `${t} of ${o.elements}` : t;
|
|
96
|
-
const flags = [];
|
|
97
|
-
if (o.required) flags.push("[required]");
|
|
98
|
-
if (o.default !== void 0 && o.default !== null)
|
|
99
|
-
flags.push(o.no_log ? "[default: (no_log)]" : `[default: ${fmtDefault(o.default)}]`);
|
|
100
|
-
const ch = choicesOf(o);
|
|
101
|
-
if (ch) flags.push(`[choices: ${ch.map((c) => String(c)).join("|")}]`);
|
|
102
|
-
if (o.aliases?.length) flags.push(`[aliases: ${o.aliases.join(", ")}]`);
|
|
103
|
-
if (o.no_log) flags.push("[no_log]");
|
|
104
|
-
if (o.deprecated) {
|
|
105
|
-
const d = o.deprecated;
|
|
106
|
-
flags.push(
|
|
107
|
-
`[deprecated${d.removed_in ? `: removed in ${d.removed_in}` : ""}${d.alternative ? `, ${oneLine(d.alternative, 80)}` : ""}]`
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
if (o.version_added && majorFloor && o.version_added_collection && newerThan(o.version_added, majorFloor)) {
|
|
111
|
-
flags.push(`[added in ${o.version_added_collection} ${o.version_added}]`);
|
|
112
|
-
}
|
|
113
|
-
const desc = oneLine(o.description, descLen);
|
|
114
|
-
return `${pad}${name} (${type})${flags.length ? ` ${flags.join(" ")}` : ""}${desc ? ` - ${desc}` : ""}`;
|
|
115
|
-
}
|
|
116
|
-
function newerThan(v, floor) {
|
|
117
|
-
const a = String(v).split(".").map(Number);
|
|
118
|
-
const b = floor.split(".").map(Number);
|
|
119
|
-
for (let i = 0; i < 3; i++) {
|
|
120
|
-
if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0);
|
|
121
|
-
}
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
function renderOptions(options, depth, descLen, majorFloor) {
|
|
125
|
-
const lines = [];
|
|
126
|
-
const pad = " ".repeat(depth);
|
|
127
|
-
for (const name of Object.keys(options).sort()) {
|
|
128
|
-
const o = options[name];
|
|
129
|
-
lines.push(optionLine(name, o, pad, descLen, majorFloor));
|
|
130
|
-
const sub = subOptionsOf(o);
|
|
131
|
-
if (sub) lines.push(...renderOptions(sub, depth + 1, descLen, majorFloor));
|
|
132
|
-
}
|
|
133
|
-
return lines;
|
|
134
|
-
}
|
|
135
|
-
function renderModuleDoc(r) {
|
|
136
|
-
const d = r.doc;
|
|
137
|
-
const resolved = r.asked !== d.fqcn ? ` [resolved from '${r.asked}']` : "";
|
|
138
|
-
let head = `${d.fqcn} (${r.type}, ${r.source})${resolved}`;
|
|
139
|
-
if (d.deprecated) {
|
|
140
|
-
const dep = d.deprecated;
|
|
141
|
-
head += ` [DEPRECATED${dep.removed_in ? `: removed in ${dep.removed_in}` : ""}${dep.why ? `; ${oneLine(dep.why, 120)}` : ""}${dep.alternative ? `; ${oneLine(dep.alternative, 120)}` : ""}]`;
|
|
142
|
-
}
|
|
143
|
-
if (d.hasAction) head += " [has action plugin]";
|
|
144
|
-
if (d.shortDescription) head += ` - ${d.shortDescription}`;
|
|
145
|
-
const lines = [head];
|
|
146
|
-
const meta = [];
|
|
147
|
-
if (d.checkMode) meta.push(`check_mode: ${d.checkMode}`);
|
|
148
|
-
if (d.requirements.length) meta.push(`requirements: ${d.requirements.join("; ")}`);
|
|
149
|
-
if (meta.length) lines.push(meta.join(" | "));
|
|
150
|
-
const opts = d.options ?? {};
|
|
151
|
-
lines.push(`options (${Object.keys(opts).length}):`);
|
|
152
|
-
lines.push(...renderOptions(opts, 1, r.descriptionChars, r.majorFloor));
|
|
153
|
-
if (r.type === "module") {
|
|
154
|
-
lines.push(
|
|
155
|
-
"not in ansible-doc output: cross-option rules (mutually_exclusive, required_if, ...); see the module description and notes"
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
if (r.includeReturn && r.type === "module") {
|
|
159
|
-
const ret = Object.entries(d.returns ?? {});
|
|
160
|
-
if (ret.length === 0) {
|
|
161
|
-
lines.push("returns: (none documented)");
|
|
162
|
-
} else {
|
|
163
|
-
lines.push(`returns (${ret.length}):`);
|
|
164
|
-
for (const [k, v] of ret.sort(([a], [b]) => a < b ? -1 : 1)) {
|
|
165
|
-
const desc = oneLine(v?.description, r.descriptionChars);
|
|
166
|
-
lines.push(
|
|
167
|
-
` ${k} (${v?.type ?? "?"}${v?.returned ? `, ${oneLine(v.returned, 40)}` : ""})${desc ? ` - ${desc}` : ""}`
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (r.includeExamples && d.examples.trim()) {
|
|
173
|
-
lines.push("examples:");
|
|
174
|
-
lines.push(...d.examples.replace(/^\n+|\s+$/g, "").split("\n"));
|
|
175
|
-
}
|
|
176
|
-
return lines.join("\n");
|
|
177
|
-
}
|
|
178
|
-
function collectionRootOf(filename) {
|
|
179
|
-
const m = /^(.*\/ansible_collections\/[^/]+\/[^/]+)\//.exec(filename.replace(/\\/g, "/"));
|
|
180
|
-
return m ? m[1] : null;
|
|
181
|
-
}
|
|
182
|
-
function collectionsPathOf(filename) {
|
|
183
|
-
const m = /^(.*)\/ansible_collections\//.exec(filename.replace(/\\/g, "/"));
|
|
184
|
-
return m ? m[1] : null;
|
|
185
|
-
}
|
|
186
|
-
var PLUGIN_TYPES = [
|
|
187
|
-
"module",
|
|
188
|
-
"lookup",
|
|
189
|
-
"filter",
|
|
190
|
-
"test",
|
|
191
|
-
"callback",
|
|
192
|
-
"connection",
|
|
193
|
-
"inventory",
|
|
194
|
-
"become",
|
|
195
|
-
"cache",
|
|
196
|
-
"vars",
|
|
197
|
-
"strategy",
|
|
198
|
-
"shell",
|
|
199
|
-
"cliconf",
|
|
200
|
-
"httpapi",
|
|
201
|
-
"netconf",
|
|
202
|
-
"keyword",
|
|
203
|
-
"role"
|
|
204
|
-
];
|
|
205
|
-
function isPluginType(t) {
|
|
206
|
-
return PLUGIN_TYPES.includes(t);
|
|
207
|
-
}
|
|
208
|
-
var BAD_TYPE_MESSAGE = `type must be one of ${PLUGIN_TYPES.join(", ")}`;
|
|
209
|
-
|
|
210
13
|
// src/redact.ts
|
|
211
14
|
var VAULTED = "<vaulted>";
|
|
212
15
|
var REDACTED_VALUE = "(redacted: contains a secret value)";
|
|
@@ -364,7 +167,7 @@ var SHAPES = [
|
|
|
364
167
|
/LS0tLS1CRUdJTi[A-Za-z0-9+/=]{0,40}(UFJJVkFURSBLRVk|BSSVZBVEUgS0VZ|UklWQVRFIEtFW)/
|
|
365
168
|
];
|
|
366
169
|
var VAULT_TEXT = /^\s*\$ANSIBLE_VAULT;/;
|
|
367
|
-
var URL_USERINFO = /\b([a-z][a-z0-9+.-]*:\/\/)([^\s:@/]
|
|
170
|
+
var URL_USERINFO = /\b([a-z][a-z0-9+.-]*:\/\/)([^\s:@/]*):([^\s@/]+)@/gi;
|
|
368
171
|
function hasSecretShape(s) {
|
|
369
172
|
return SHAPES.some((re) => re.test(s));
|
|
370
173
|
}
|
|
@@ -492,11 +295,13 @@ var Redactor = class {
|
|
|
492
295
|
const url = maskUrlPasswords(v);
|
|
493
296
|
if (url !== null) this.counts.url++;
|
|
494
297
|
const inline = maskInlineCredentials(url ?? v);
|
|
495
|
-
if (inline !== null)
|
|
496
|
-
|
|
497
|
-
|
|
298
|
+
if (inline !== null) this.counts.shape++;
|
|
299
|
+
const masked = inline ?? url;
|
|
300
|
+
if (masked !== null) {
|
|
301
|
+
if (!this.matches(masked)) return masked;
|
|
302
|
+
this.counts.value++;
|
|
303
|
+
return new Hidden(REDACTED_VALUE);
|
|
498
304
|
}
|
|
499
|
-
if (url !== null) return url;
|
|
500
305
|
if (this.matches(v)) {
|
|
501
306
|
this.counts.value++;
|
|
502
307
|
return new Hidden(REDACTED_VALUE);
|
|
@@ -542,11 +347,212 @@ var Redactor = class {
|
|
|
542
347
|
return parts.length ? `redacted: ${parts.join(", ")}` : "";
|
|
543
348
|
}
|
|
544
349
|
};
|
|
350
|
+
function redactStandalone(value, key) {
|
|
351
|
+
const red = new Redactor();
|
|
352
|
+
red.learn(value, [key]);
|
|
353
|
+
return red.render(value, [key]);
|
|
354
|
+
}
|
|
545
355
|
function stringify(v) {
|
|
546
356
|
if (v instanceof Hidden) return v.text;
|
|
547
357
|
return JSON.stringify(v, (_k, x) => x instanceof Hidden ? x.text : x) ?? "null";
|
|
548
358
|
}
|
|
549
359
|
|
|
360
|
+
// src/ansibleDoc.ts
|
|
361
|
+
var asText = (d) => Array.isArray(d) ? d.map(String).join(" ") : typeof d === "string" ? d : d === void 0 || d === null ? "" : String(d);
|
|
362
|
+
function parseDocJson(text2) {
|
|
363
|
+
const out = /* @__PURE__ */ new Map();
|
|
364
|
+
const t = text2.trim();
|
|
365
|
+
if (!t) return out;
|
|
366
|
+
let data;
|
|
367
|
+
try {
|
|
368
|
+
data = JSON.parse(t);
|
|
369
|
+
} catch (e) {
|
|
370
|
+
throw new Error(`ansible-doc --json did not return JSON (${e instanceof Error ? e.message : String(e)}).`);
|
|
371
|
+
}
|
|
372
|
+
for (const [key, entry] of Object.entries(data ?? {})) {
|
|
373
|
+
const doc = entry?.doc;
|
|
374
|
+
if (!doc || typeof doc !== "object") continue;
|
|
375
|
+
out.set(key, {
|
|
376
|
+
key,
|
|
377
|
+
fqcn: String(doc.plugin_name ?? key),
|
|
378
|
+
collection: String(doc.collection ?? ""),
|
|
379
|
+
filename: String(doc.filename ?? ""),
|
|
380
|
+
hasAction: doc.has_action === true,
|
|
381
|
+
shortDescription: asText(doc.short_description),
|
|
382
|
+
description: asText(doc.description),
|
|
383
|
+
options: doc.options ?? {},
|
|
384
|
+
deprecated: doc.deprecated && typeof doc.deprecated === "object" ? doc.deprecated : void 0,
|
|
385
|
+
checkMode: doc.attributes?.check_mode?.support,
|
|
386
|
+
requirements: Array.isArray(doc.requirements) ? doc.requirements.map(String) : [],
|
|
387
|
+
returns: entry.return && typeof entry.return === "object" ? entry.return : null,
|
|
388
|
+
examples: typeof entry.examples === "string" ? entry.examples : "",
|
|
389
|
+
versionAdded: doc.version_added
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
return out;
|
|
393
|
+
}
|
|
394
|
+
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]+?)\.?$/;
|
|
395
|
+
function classifyDocStderr(stderr) {
|
|
396
|
+
const r = { missing: [], deprecations: [], tombstones: [], errors: [] };
|
|
397
|
+
for (const line of stderr.split(/\r?\n/)) {
|
|
398
|
+
let m = /^\[WARNING\]: (\S+) was not found$/.exec(line);
|
|
399
|
+
if (m) {
|
|
400
|
+
if (!r.missing.includes(m[1])) r.missing.push(m[1]);
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
m = /^\[DEPRECATION WARNING\]: (\S+) has been deprecated\. (.*)$/.exec(line);
|
|
404
|
+
if (m) {
|
|
405
|
+
r.deprecations.push({ name: m[1], text: m[2] });
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
m = TOMBSTONE.exec(line);
|
|
409
|
+
if (m) {
|
|
410
|
+
if (!r.tombstones.some((t) => t.name === m[1])) {
|
|
411
|
+
r.tombstones.push({ name: m[1], text: m[2].trim(), collection: m[3], version: m[4] });
|
|
412
|
+
}
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
if (line.startsWith("[ERROR]:")) r.errors.push(line.slice(9).trim());
|
|
416
|
+
}
|
|
417
|
+
return r;
|
|
418
|
+
}
|
|
419
|
+
function choicesOf(o) {
|
|
420
|
+
if (!o?.choices) return null;
|
|
421
|
+
return Array.isArray(o.choices) ? o.choices : Object.keys(o.choices);
|
|
422
|
+
}
|
|
423
|
+
function subOptionsOf(o) {
|
|
424
|
+
return o?.suboptions ?? o?.options ?? null;
|
|
425
|
+
}
|
|
426
|
+
var typeOf = (o) => o?.type ?? "str";
|
|
427
|
+
function findOption(options, name) {
|
|
428
|
+
if (Object.hasOwn(options, name)) return [name, options[name], void 0];
|
|
429
|
+
for (const [k, o] of Object.entries(options)) {
|
|
430
|
+
if (o.aliases?.includes(name)) return [k, o, name];
|
|
431
|
+
}
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
function oneLine(desc, max) {
|
|
435
|
+
let d = asText(desc).replace(/\s+/g, " ").trim();
|
|
436
|
+
if (max && d.length > max) d = `${d.slice(0, max)}...`;
|
|
437
|
+
return d;
|
|
438
|
+
}
|
|
439
|
+
function optionLine(name, o, pad, descLen, majorFloor) {
|
|
440
|
+
const t = typeOf(o);
|
|
441
|
+
const type = o.elements ? `${t} of ${o.elements}` : t;
|
|
442
|
+
const flags = [];
|
|
443
|
+
if (o.required) flags.push("[required]");
|
|
444
|
+
if (o.default !== void 0 && o.default !== null)
|
|
445
|
+
flags.push(o.no_log ? "[default: (no_log)]" : `[default: ${redactStandalone(o.default, name)}]`);
|
|
446
|
+
const ch = choicesOf(o);
|
|
447
|
+
if (ch) flags.push(`[choices: ${ch.map((c) => String(c)).join("|")}]`);
|
|
448
|
+
if (o.aliases?.length) flags.push(`[aliases: ${o.aliases.join(", ")}]`);
|
|
449
|
+
if (o.no_log) flags.push("[no_log]");
|
|
450
|
+
if (o.deprecated) {
|
|
451
|
+
const d = o.deprecated;
|
|
452
|
+
flags.push(
|
|
453
|
+
`[deprecated${d.removed_in ? `: removed in ${d.removed_in}` : ""}${d.alternative ? `, ${oneLine(d.alternative, 80)}` : ""}]`
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
if (o.version_added && majorFloor && o.version_added_collection && newerThan(o.version_added, majorFloor)) {
|
|
457
|
+
flags.push(`[added in ${o.version_added_collection} ${o.version_added}]`);
|
|
458
|
+
}
|
|
459
|
+
const desc = oneLine(o.description, descLen);
|
|
460
|
+
return `${pad}${name} (${type})${flags.length ? ` ${flags.join(" ")}` : ""}${desc ? ` - ${desc}` : ""}`;
|
|
461
|
+
}
|
|
462
|
+
function newerThan(v, floor) {
|
|
463
|
+
const a = String(v).split(".").map(Number);
|
|
464
|
+
const b = floor.split(".").map(Number);
|
|
465
|
+
for (let i = 0; i < 3; i++) {
|
|
466
|
+
if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0);
|
|
467
|
+
}
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
function renderOptions(options, depth, descLen, majorFloor) {
|
|
471
|
+
const lines = [];
|
|
472
|
+
const pad = " ".repeat(depth);
|
|
473
|
+
for (const name of Object.keys(options).sort()) {
|
|
474
|
+
const o = options[name];
|
|
475
|
+
lines.push(optionLine(name, o, pad, descLen, majorFloor));
|
|
476
|
+
const sub = subOptionsOf(o);
|
|
477
|
+
if (sub) lines.push(...renderOptions(sub, depth + 1, descLen, majorFloor));
|
|
478
|
+
}
|
|
479
|
+
return lines;
|
|
480
|
+
}
|
|
481
|
+
function renderModuleDoc(r) {
|
|
482
|
+
const d = r.doc;
|
|
483
|
+
const resolved = r.asked !== d.fqcn ? ` [resolved from '${r.asked}']` : "";
|
|
484
|
+
let head = `${d.fqcn} (${r.type}, ${r.source})${resolved}`;
|
|
485
|
+
if (d.deprecated) {
|
|
486
|
+
const dep = d.deprecated;
|
|
487
|
+
head += ` [DEPRECATED${dep.removed_in ? `: removed in ${dep.removed_in}` : ""}${dep.why ? `; ${oneLine(dep.why, 120)}` : ""}${dep.alternative ? `; ${oneLine(dep.alternative, 120)}` : ""}]`;
|
|
488
|
+
}
|
|
489
|
+
if (d.hasAction) head += " [has action plugin]";
|
|
490
|
+
if (d.shortDescription) head += ` - ${d.shortDescription}`;
|
|
491
|
+
const lines = [head];
|
|
492
|
+
const meta = [];
|
|
493
|
+
if (d.checkMode) meta.push(`check_mode: ${d.checkMode}`);
|
|
494
|
+
if (d.requirements.length) meta.push(`requirements: ${d.requirements.join("; ")}`);
|
|
495
|
+
if (meta.length) lines.push(meta.join(" | "));
|
|
496
|
+
const opts = d.options ?? {};
|
|
497
|
+
lines.push(`options (${Object.keys(opts).length}):`);
|
|
498
|
+
lines.push(...renderOptions(opts, 1, r.descriptionChars, r.majorFloor));
|
|
499
|
+
if (r.type === "module") {
|
|
500
|
+
lines.push(
|
|
501
|
+
"not in ansible-doc output: cross-option rules (mutually_exclusive, required_if, ...); see the module description and notes"
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
if (r.includeReturn && r.type === "module") {
|
|
505
|
+
const ret = Object.entries(d.returns ?? {});
|
|
506
|
+
if (ret.length === 0) {
|
|
507
|
+
lines.push("returns: (none documented)");
|
|
508
|
+
} else {
|
|
509
|
+
lines.push(`returns (${ret.length}):`);
|
|
510
|
+
for (const [k, v] of ret.sort(([a], [b]) => a < b ? -1 : 1)) {
|
|
511
|
+
const desc = oneLine(v?.description, r.descriptionChars);
|
|
512
|
+
lines.push(
|
|
513
|
+
` ${k} (${v?.type ?? "?"}${v?.returned ? `, ${oneLine(v.returned, 40)}` : ""})${desc ? ` - ${desc}` : ""}`
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
if (r.includeExamples && d.examples.trim()) {
|
|
519
|
+
lines.push("examples:");
|
|
520
|
+
lines.push(...d.examples.replace(/^\n+|\s+$/g, "").split("\n"));
|
|
521
|
+
}
|
|
522
|
+
return lines.join("\n");
|
|
523
|
+
}
|
|
524
|
+
function collectionRootOf(filename) {
|
|
525
|
+
const m = /^(.*\/ansible_collections\/[^/]+\/[^/]+)\//.exec(filename.replace(/\\/g, "/"));
|
|
526
|
+
return m ? m[1] : null;
|
|
527
|
+
}
|
|
528
|
+
function collectionsPathOf(filename) {
|
|
529
|
+
const m = /^(.*)\/ansible_collections\//.exec(filename.replace(/\\/g, "/"));
|
|
530
|
+
return m ? m[1] : null;
|
|
531
|
+
}
|
|
532
|
+
var PLUGIN_TYPES = [
|
|
533
|
+
"module",
|
|
534
|
+
"lookup",
|
|
535
|
+
"filter",
|
|
536
|
+
"test",
|
|
537
|
+
"callback",
|
|
538
|
+
"connection",
|
|
539
|
+
"inventory",
|
|
540
|
+
"become",
|
|
541
|
+
"cache",
|
|
542
|
+
"vars",
|
|
543
|
+
"strategy",
|
|
544
|
+
"shell",
|
|
545
|
+
"cliconf",
|
|
546
|
+
"httpapi",
|
|
547
|
+
"netconf",
|
|
548
|
+
"keyword",
|
|
549
|
+
"role"
|
|
550
|
+
];
|
|
551
|
+
function isPluginType(t) {
|
|
552
|
+
return PLUGIN_TYPES.includes(t);
|
|
553
|
+
}
|
|
554
|
+
var BAD_TYPE_MESSAGE = `type must be one of ${PLUGIN_TYPES.join(", ")}`;
|
|
555
|
+
|
|
550
556
|
// src/config.ts
|
|
551
557
|
function parseConfigDump(text2) {
|
|
552
558
|
let data;
|
|
@@ -961,24 +967,44 @@ var AnsibleRunner = class {
|
|
|
961
967
|
const d = this.distro();
|
|
962
968
|
return d ? `\\\\wsl.localhost\\${d}${p.replace(/\//g, "\\")}` : null;
|
|
963
969
|
}
|
|
964
|
-
/**
|
|
970
|
+
/**
|
|
971
|
+
* The Ansible side's environment (prefix mode; learned once per process). A
|
|
972
|
+
* spawn failure, a non-zero exit or an empty listing rejects and is not
|
|
973
|
+
* cached, so the next call asks again.
|
|
974
|
+
*/
|
|
965
975
|
sideEnv() {
|
|
966
976
|
if (!this.prefixed) return Promise.resolve(process.env);
|
|
967
|
-
this.sideEnvCache
|
|
968
|
-
const
|
|
969
|
-
|
|
970
|
-
const
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
977
|
+
if (!this.sideEnvCache) {
|
|
978
|
+
const p = this.raw("env", [], {}).then((r) => {
|
|
979
|
+
const out = {};
|
|
980
|
+
for (const line of r.stdout.split("\n")) {
|
|
981
|
+
const i = line.indexOf("=");
|
|
982
|
+
if (i > 0) out[line.slice(0, i)] = line.slice(i + 1);
|
|
983
|
+
}
|
|
984
|
+
if (r.code !== 0 || Object.keys(out).length === 0) {
|
|
985
|
+
throw new Error(
|
|
986
|
+
`could not read the Ansible side's environment (env exit ${r.code})${r.stderr.trim() ? `: ${r.stderr.trim().slice(0, 512)}` : ""}`
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
return out;
|
|
990
|
+
});
|
|
991
|
+
p.catch(() => {
|
|
992
|
+
this.sideEnvCache = null;
|
|
993
|
+
});
|
|
994
|
+
this.sideEnvCache = p;
|
|
995
|
+
}
|
|
975
996
|
return this.sideEnvCache;
|
|
976
997
|
}
|
|
977
998
|
/** Ansible-side cache root: ANSIBLE_MCP_REMOTE_CACHE, else $HOME/.cache/ansible-mcp (never /tmp, F24). */
|
|
978
999
|
async sideCacheRoot() {
|
|
979
1000
|
if (!this.prefixed) return this.localCache;
|
|
980
1001
|
if (this.remoteCacheOverride) return this.remoteCacheOverride;
|
|
981
|
-
const home = (await this.sideEnv()).HOME
|
|
1002
|
+
const home = (await this.sideEnv()).HOME;
|
|
1003
|
+
if (!home) {
|
|
1004
|
+
throw new Error(
|
|
1005
|
+
"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."
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
982
1008
|
return posix.join(home, ".cache", "ansible-mcp");
|
|
983
1009
|
}
|
|
984
1010
|
/**
|
|
@@ -1126,10 +1152,17 @@ var AnsibleRunner = class {
|
|
|
1126
1152
|
const r = await this.raw("mv", ["-T", "--", from, to], {});
|
|
1127
1153
|
return r.code === 0;
|
|
1128
1154
|
}
|
|
1129
|
-
/**
|
|
1155
|
+
/**
|
|
1156
|
+
* Recursive delete of a `.tmp-*` dir, only under `guardRoot` (asserted): the
|
|
1157
|
+
* last segment must start with `.tmp-`, and no segment of either path may be
|
|
1158
|
+
* `.` or `..` (a plain prefix test would accept `<root>/../x/.tmp-y`).
|
|
1159
|
+
*/
|
|
1130
1160
|
async sideRemoveTemp(p, guardRoot) {
|
|
1131
|
-
const
|
|
1132
|
-
|
|
1161
|
+
const segs = (s) => s.replace(/\\/g, "/").replace(/\/+$/, "").split("/");
|
|
1162
|
+
const ps = segs(p);
|
|
1163
|
+
const rs = segs(guardRoot);
|
|
1164
|
+
const dotted = (x) => x.some((s) => s === "." || s === "..");
|
|
1165
|
+
if (dotted(ps) || dotted(rs) || ps.length <= rs.length || rs.some((s, i) => s !== ps[i]) || !ps.at(-1).startsWith(".tmp-")) {
|
|
1133
1166
|
throw new Error(`refusing to remove ${p}: not a temp dir under ${guardRoot}`);
|
|
1134
1167
|
}
|
|
1135
1168
|
if (!this.prefixed) {
|
|
@@ -1174,6 +1207,7 @@ var AnsibleContext = class {
|
|
|
1174
1207
|
configCache = /* @__PURE__ */ new Map();
|
|
1175
1208
|
versionCache = null;
|
|
1176
1209
|
fingerprints = /* @__PURE__ */ new Map();
|
|
1210
|
+
/** Per-name doc results; `deprecations` replays the batch's warnings naming that entry on a hit. */
|
|
1177
1211
|
docCache = /* @__PURE__ */ new Map();
|
|
1178
1212
|
listCache = /* @__PURE__ */ new Map();
|
|
1179
1213
|
/** Serializes ansible_upgrade_impact calls in this process. */
|
|
@@ -1331,6 +1365,9 @@ ${r.stderr.trim().slice(0, 2048)}`);
|
|
|
1331
1365
|
* tombstone retry (F2: one tombstone fails the whole batch, so it is recorded
|
|
1332
1366
|
* and the batch re-run without it). `collectionsPath` overrides
|
|
1333
1367
|
* ANSIBLE_COLLECTIONS_PATH (upgrade targets); those results are not cached.
|
|
1368
|
+
* A name starting with `-` is never a plugin name: it is reported missing and
|
|
1369
|
+
* never reaches argv (task keys are user data; `-M x` would be an option), and
|
|
1370
|
+
* the names follow `--` besides.
|
|
1334
1371
|
*/
|
|
1335
1372
|
async docs(p, names, opts = {}) {
|
|
1336
1373
|
const type = opts.type ?? "module";
|
|
@@ -1340,20 +1377,31 @@ ${r.stderr.trim().slice(0, 2048)}`);
|
|
|
1340
1377
|
const fp = cacheable ? await this.fingerprint(p) : "";
|
|
1341
1378
|
const todo = [];
|
|
1342
1379
|
for (const n of unique) {
|
|
1380
|
+
if (n.startsWith("-")) {
|
|
1381
|
+
result.missing.push(n);
|
|
1382
|
+
continue;
|
|
1383
|
+
}
|
|
1343
1384
|
const c = cacheable ? this.docCache.get(`${fp}|${type}|${n}`) : void 0;
|
|
1344
1385
|
if (!c) todo.push(n);
|
|
1345
|
-
else if ("kind" in c
|
|
1346
|
-
|
|
1347
|
-
|
|
1386
|
+
else if ("kind" in c) {
|
|
1387
|
+
if (c.kind === "doc" && c.doc) result.docs.set(n, c.doc);
|
|
1388
|
+
else result.missing.push(n);
|
|
1389
|
+
result.deprecations.push(...c.deprecations);
|
|
1390
|
+
} else result.tombstones.push(c);
|
|
1348
1391
|
}
|
|
1349
1392
|
const env = {};
|
|
1350
1393
|
if (opts.collectionsPath) env.ANSIBLE_COLLECTIONS_PATH = opts.collectionsPath;
|
|
1351
1394
|
for (let i = 0; i < todo.length; i += DOC_BATCH) {
|
|
1352
1395
|
let batch = todo.slice(i, i + DOC_BATCH);
|
|
1353
1396
|
for (let attempt = 0; batch.length > 0 && attempt <= batch.length; attempt++) {
|
|
1354
|
-
const r = await this.runSafe(
|
|
1355
|
-
|
|
1356
|
-
|
|
1397
|
+
const r = await this.runSafe(
|
|
1398
|
+
p,
|
|
1399
|
+
"ansible-doc",
|
|
1400
|
+
["--json", "-t", type, ...opts.extraArgs ?? [], "--", ...batch],
|
|
1401
|
+
{
|
|
1402
|
+
env
|
|
1403
|
+
}
|
|
1404
|
+
);
|
|
1357
1405
|
const st = classifyDocStderr(r.stderr);
|
|
1358
1406
|
if (r.code !== 0) {
|
|
1359
1407
|
const tomb = st.tombstones.filter((t) => batch.includes(t.name));
|
|
@@ -1371,12 +1419,14 @@ ${r.stderr.trim().slice(0, 2048)}`);
|
|
|
1371
1419
|
const docs = parseDocJson(r.stdout);
|
|
1372
1420
|
for (const n of batch) {
|
|
1373
1421
|
const d = docs.get(n);
|
|
1374
|
-
if (d)
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1422
|
+
if (d) result.docs.set(n, d);
|
|
1423
|
+
else result.missing.push(n);
|
|
1424
|
+
if (cacheable) {
|
|
1425
|
+
const deprecations = st.deprecations.filter((x) => x.name === n);
|
|
1426
|
+
this.docCache.set(
|
|
1427
|
+
`${fp}|${type}|${n}`,
|
|
1428
|
+
d ? { kind: "doc", doc: d, deprecations } : { kind: "missing", deprecations }
|
|
1429
|
+
);
|
|
1380
1430
|
}
|
|
1381
1431
|
}
|
|
1382
1432
|
result.deprecations.push(...st.deprecations);
|
|
@@ -1422,11 +1472,11 @@ import { z } from "zod";
|
|
|
1422
1472
|
|
|
1423
1473
|
// src/handlers.ts
|
|
1424
1474
|
import { readdirSync as readdirSync5, readFileSync as readFileSync4 } from "fs";
|
|
1425
|
-
import { dirname as dirname3, join as join6 } from "path";
|
|
1475
|
+
import { dirname as dirname3, join as join6, normalize } from "path";
|
|
1426
1476
|
|
|
1427
1477
|
// src/project.ts
|
|
1428
|
-
import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync2, statSync as statSync2 } from "fs";
|
|
1429
|
-
import { dirname, join as join2, posix as posix2 } from "path";
|
|
1478
|
+
import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync2, realpathSync, statSync as statSync2 } from "fs";
|
|
1479
|
+
import { dirname, isAbsolute, join as join2, posix as posix2 } from "path";
|
|
1430
1480
|
|
|
1431
1481
|
// src/yaml.ts
|
|
1432
1482
|
import {
|
|
@@ -1464,6 +1514,8 @@ var pyFalse = {
|
|
|
1464
1514
|
resolve: () => false
|
|
1465
1515
|
};
|
|
1466
1516
|
var NULL_SCALAR = (line) => ({ kind: "scalar", value: null, line, raw: "" });
|
|
1517
|
+
var MAX_ALIAS_EXPANSION = 1e5;
|
|
1518
|
+
var ALIAS_LIMIT_ERROR = "alias expansion limit exceeded";
|
|
1467
1519
|
function parseYaml(src) {
|
|
1468
1520
|
const lc = new LineCounter();
|
|
1469
1521
|
const docs = parseAllDocuments(src, {
|
|
@@ -1487,6 +1539,16 @@ function parseYaml(src) {
|
|
|
1487
1539
|
const line = (offset) => offset === void 0 ? 0 : lc.linePos(offset).line;
|
|
1488
1540
|
const convertedCache = /* @__PURE__ */ new WeakMap();
|
|
1489
1541
|
const inProgress = /* @__PURE__ */ new WeakSet();
|
|
1542
|
+
const sizes = /* @__PURE__ */ new WeakMap();
|
|
1543
|
+
let aliasBudget = MAX_ALIAS_EXPANSION;
|
|
1544
|
+
let aliasLimitHit = false;
|
|
1545
|
+
const sizeOf = (y) => {
|
|
1546
|
+
const known = sizes.get(y);
|
|
1547
|
+
if (known !== void 0) return known;
|
|
1548
|
+
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);
|
|
1549
|
+
sizes.set(y, n);
|
|
1550
|
+
return n;
|
|
1551
|
+
};
|
|
1490
1552
|
const mergeEntries = (node) => {
|
|
1491
1553
|
const anchors = isAlias(node) ? [node] : isSeq(node) ? node.items : [];
|
|
1492
1554
|
const out = [];
|
|
@@ -1498,10 +1560,23 @@ function parseYaml(src) {
|
|
|
1498
1560
|
}
|
|
1499
1561
|
return out;
|
|
1500
1562
|
};
|
|
1563
|
+
const aliasKey = (k, fallbackLine) => {
|
|
1564
|
+
const conv = convert(k, fallbackLine);
|
|
1565
|
+
return conv.kind === "scalar" && conv.value !== null && typeof conv.value !== "object" ? String(conv.value) : String(k);
|
|
1566
|
+
};
|
|
1501
1567
|
const convert = (node, fallbackLine) => {
|
|
1502
1568
|
if (node === null || node === void 0) return NULL_SCALAR(fallbackLine);
|
|
1503
1569
|
if (isAlias(node)) {
|
|
1504
|
-
|
|
1570
|
+
const target = node.resolve(docs[0]);
|
|
1571
|
+
const aliasLine = line(node.range?.[0]);
|
|
1572
|
+
if (!target || aliasLimitHit) return NULL_SCALAR(aliasLine);
|
|
1573
|
+
const out = convert(target, aliasLine);
|
|
1574
|
+
aliasBudget -= sizeOf(out);
|
|
1575
|
+
if (aliasBudget < 0) {
|
|
1576
|
+
aliasLimitHit = true;
|
|
1577
|
+
return NULL_SCALAR(aliasLine);
|
|
1578
|
+
}
|
|
1579
|
+
return out;
|
|
1505
1580
|
}
|
|
1506
1581
|
const n = node;
|
|
1507
1582
|
const cached = convertedCache.get(n);
|
|
@@ -1535,7 +1610,7 @@ function parseYaml(src) {
|
|
|
1535
1610
|
for (const e of mergeEntries(item.value)) merged.push(e);
|
|
1536
1611
|
continue;
|
|
1537
1612
|
}
|
|
1538
|
-
const keyText = isScalar(k) ? String(k.value) : k ? String(k) : "";
|
|
1613
|
+
const keyText = isScalar(k) ? String(k.value) : isAlias(k) ? aliasKey(k, start) : k ? String(k) : "";
|
|
1539
1614
|
const keyLine = line(k?.range?.[0]) || start;
|
|
1540
1615
|
if (seen.has(keyText)) duplicates.push({ key: keyText, line: keyLine });
|
|
1541
1616
|
seen.add(keyText);
|
|
@@ -1574,6 +1649,7 @@ function parseYaml(src) {
|
|
|
1574
1649
|
for (const e of d.errors) errors.push(e.message.split("\n")[0]);
|
|
1575
1650
|
if (i === 0) root = d.contents ? convert(d.contents, 1) : null;
|
|
1576
1651
|
}
|
|
1652
|
+
if (aliasLimitHit) errors.push(`${ALIAS_LIMIT_ERROR} (more than ${MAX_ALIAS_EXPANSION} nodes through aliases)`);
|
|
1577
1653
|
return { root, errors, duplicates };
|
|
1578
1654
|
}
|
|
1579
1655
|
function toJS(node) {
|
|
@@ -1680,6 +1756,38 @@ function isFreeForm(fqcnOrName) {
|
|
|
1680
1756
|
}
|
|
1681
1757
|
return FREE_FORM.has(parts[parts.length - 1]);
|
|
1682
1758
|
}
|
|
1759
|
+
var CHECK_RAW_MODULES = /* @__PURE__ */ new Set(["command", "raw", "script", "shell", "win_command", "win_shell"]);
|
|
1760
|
+
var CHECK_RAW_OPTIONS = /* @__PURE__ */ new Set([
|
|
1761
|
+
"creates",
|
|
1762
|
+
"removes",
|
|
1763
|
+
"chdir",
|
|
1764
|
+
"executable",
|
|
1765
|
+
"warn",
|
|
1766
|
+
"stdin",
|
|
1767
|
+
"stdin_add_newline",
|
|
1768
|
+
"strip_empty_ends"
|
|
1769
|
+
]);
|
|
1770
|
+
function isCheckRawAction(action) {
|
|
1771
|
+
const parts = action.split(".");
|
|
1772
|
+
if (parts.length === 1) return CHECK_RAW_MODULES.has(action);
|
|
1773
|
+
if (parts.length !== 3) return false;
|
|
1774
|
+
if (parts[0] === "ansible" && (parts[1] === "builtin" || parts[1] === "legacy"))
|
|
1775
|
+
return CHECK_RAW_MODULES.has(parts[2]);
|
|
1776
|
+
return parts[0] === "ansible" && parts[1] === "windows" && /^win_(command|shell)$/.test(parts[2]);
|
|
1777
|
+
}
|
|
1778
|
+
var IMPORT_PLAYBOOK_KEYS = [
|
|
1779
|
+
"import_playbook",
|
|
1780
|
+
"ansible.builtin.import_playbook",
|
|
1781
|
+
"ansible.legacy.import_playbook"
|
|
1782
|
+
];
|
|
1783
|
+
var isPlayKey = (k) => k === "hosts" || IMPORT_PLAYBOOK_KEYS.includes(k);
|
|
1784
|
+
function importPlaybookEntry(play) {
|
|
1785
|
+
if (play.kind !== "map") return void 0;
|
|
1786
|
+
for (let i = play.entries.length - 1; i >= 0; i--) {
|
|
1787
|
+
if (IMPORT_PLAYBOOK_KEYS.includes(play.entries[i].key)) return play.entries[i].value;
|
|
1788
|
+
}
|
|
1789
|
+
return void 0;
|
|
1790
|
+
}
|
|
1683
1791
|
var INCLUDE_TASKS = /* @__PURE__ */ new Set(["include_tasks", "import_tasks", "include"]);
|
|
1684
1792
|
var INCLUDE_ROLE = /* @__PURE__ */ new Set(["include_role", "import_role"]);
|
|
1685
1793
|
var builtinName = (a) => a.replace(/^ansible\.(builtin|legacy)\./, "");
|
|
@@ -1731,7 +1839,7 @@ function unquote(v) {
|
|
|
1731
1839
|
if (v.length >= 2 && (v[0] === '"' || v[0] === "'") && v[v.length - 1] === v[0]) return v.slice(1, -1);
|
|
1732
1840
|
return v;
|
|
1733
1841
|
}
|
|
1734
|
-
function parseKv(s) {
|
|
1842
|
+
function parseKv(s, checkRaw = false) {
|
|
1735
1843
|
const options = {};
|
|
1736
1844
|
const raw = [];
|
|
1737
1845
|
for (const tok of splitArgs(s)) {
|
|
@@ -1747,7 +1855,7 @@ function parseKv(s) {
|
|
|
1747
1855
|
continue;
|
|
1748
1856
|
}
|
|
1749
1857
|
const k = tok.slice(0, pos).trim();
|
|
1750
|
-
if (/["']/.test(k)) {
|
|
1858
|
+
if (/["']/.test(k) || checkRaw && !CHECK_RAW_OPTIONS.has(k)) {
|
|
1751
1859
|
raw.push(tok);
|
|
1752
1860
|
continue;
|
|
1753
1861
|
}
|
|
@@ -1803,14 +1911,20 @@ function extractTask(map, file, doc, extra = {}) {
|
|
|
1803
1911
|
if (v.kind === "scalar" && typeof v.value === "string") {
|
|
1804
1912
|
const [mod, ...rest] = splitArgs(v.value);
|
|
1805
1913
|
t.action = mod;
|
|
1806
|
-
const kv = parseKv(rest.join(" "));
|
|
1914
|
+
const kv = parseKv(rest.join(" "), !!mod && isCheckRawAction(mod));
|
|
1807
1915
|
t.form = "kv";
|
|
1808
1916
|
t.args = Object.entries(kv).map(([k, val]) => ({ name: k, line: v.line, value: val }));
|
|
1809
1917
|
} else if (v.kind === "map") {
|
|
1810
|
-
const
|
|
1918
|
+
const modNode = get(v, "module");
|
|
1919
|
+
const [mod, ...rest] = splitArgs(scalarString(modNode) ?? "");
|
|
1811
1920
|
if (mod) t.action = mod;
|
|
1812
1921
|
t.form = "dict";
|
|
1813
1922
|
t.args = v.entries.filter((e) => e.key !== "module").map((e) => entryArg(e.key, e.keyLine, e.value));
|
|
1923
|
+
if (mod && rest.length > 0) {
|
|
1924
|
+
const kv = parseKv(rest.join(" "), isCheckRawAction(mod));
|
|
1925
|
+
t.args = t.args.filter((a) => !(a.name in kv));
|
|
1926
|
+
for (const [k, val] of Object.entries(kv)) t.args.push({ name: k, line: modNode.line, value: val });
|
|
1927
|
+
}
|
|
1814
1928
|
}
|
|
1815
1929
|
if (actions.length > 0) t.conflicting = [actionKw.key, ...actions.map((a) => a.key)];
|
|
1816
1930
|
} else if (actions.length > 0) {
|
|
@@ -1827,12 +1941,18 @@ function extractTask(map, file, doc, extra = {}) {
|
|
|
1827
1941
|
} else if (actionNode.kind === "scalar" && actionNode.value !== null && actionNode.value !== void 0) {
|
|
1828
1942
|
t.form = "kv";
|
|
1829
1943
|
const text2 = typeof actionNode.value === "string" ? actionNode.value : String(actionNode.value);
|
|
1830
|
-
t.args = Object.entries(parseKv(text2)).map(([k, val]) => ({
|
|
1944
|
+
t.args = Object.entries(parseKv(text2, isCheckRawAction(t.action))).map(([k, val]) => ({
|
|
1945
|
+
name: k,
|
|
1946
|
+
line: actionNode.line,
|
|
1947
|
+
value: val
|
|
1948
|
+
}));
|
|
1831
1949
|
}
|
|
1832
1950
|
}
|
|
1833
1951
|
const argsKw = get(map, "args");
|
|
1834
1952
|
if (argsKw?.kind === "map") {
|
|
1953
|
+
const own = new Set(t.args.map((a) => a.name));
|
|
1835
1954
|
for (const e of argsKw.entries) {
|
|
1955
|
+
if (own.has(e.key)) continue;
|
|
1836
1956
|
t.args = t.args.filter((a) => a.name !== e.key);
|
|
1837
1957
|
t.args.push(entryArg(e.key, e.keyLine, e.value));
|
|
1838
1958
|
}
|
|
@@ -1875,11 +1995,11 @@ function tasksOf(seq, file, doc, extra = {}) {
|
|
|
1875
1995
|
}
|
|
1876
1996
|
function isPlaybookRoot(root) {
|
|
1877
1997
|
if (root?.kind !== "seq" || root.items.length === 0) return false;
|
|
1878
|
-
return root.items.every(
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
);
|
|
1998
|
+
return root.items.every((i) => i.kind === "map" && i.entries.some((e) => isPlayKey(e.key)));
|
|
1999
|
+
}
|
|
2000
|
+
function isPlaybookLike(root) {
|
|
2001
|
+
if (root?.kind !== "seq") return false;
|
|
2002
|
+
return root.items.some((i) => i.kind === "map" && i.entries.some((e) => isPlayKey(e.key)));
|
|
1883
2003
|
}
|
|
1884
2004
|
var MAX_YAML_BYTES = 2 * 1024 * 1024;
|
|
1885
2005
|
var ProjectFiles = class {
|
|
@@ -1887,25 +2007,37 @@ var ProjectFiles = class {
|
|
|
1887
2007
|
this.dir = dir;
|
|
1888
2008
|
}
|
|
1889
2009
|
dir;
|
|
2010
|
+
/** Per path: the parsed doc (null when unread), and the file size (undefined when not a readable file). */
|
|
1890
2011
|
cache = /* @__PURE__ */ new Map();
|
|
2012
|
+
/** An absolute input is returned unchanged (a playbook outside dir); a relative one joins dir. */
|
|
1891
2013
|
abs(rel) {
|
|
1892
|
-
return join2(this.dir, rel);
|
|
2014
|
+
return isAbsolute(rel) ? rel : join2(this.dir, rel);
|
|
1893
2015
|
}
|
|
2016
|
+
/** Relative to dir when inside it (drive-letter / case-insensitive on Windows), else the forward-slashed path. */
|
|
1894
2017
|
rel(abs) {
|
|
1895
2018
|
const a = abs.replace(/\\/g, "/");
|
|
1896
2019
|
const b = this.dir.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
2020
|
+
const fold = (x) => process.platform === "win32" ? x.toLowerCase() : x;
|
|
2021
|
+
return fold(a).startsWith(fold(`${b}/`)) ? a.slice(b.length + 1) : a;
|
|
2022
|
+
}
|
|
2023
|
+
/** Parse a YAML file of at most `maxBytes` (default 2 MiB); null when missing, unreadable or larger. */
|
|
2024
|
+
read(abs, maxBytes = MAX_YAML_BYTES) {
|
|
2025
|
+
const hit = this.cache.get(abs);
|
|
2026
|
+
if (hit && (hit.size === void 0 || hit.size > maxBytes)) return null;
|
|
2027
|
+
if (hit?.doc) return hit.doc;
|
|
1901
2028
|
let doc = null;
|
|
2029
|
+
let size;
|
|
1902
2030
|
try {
|
|
1903
2031
|
const st = statSync2(abs);
|
|
1904
|
-
if (st.isFile()
|
|
2032
|
+
if (st.isFile()) {
|
|
2033
|
+
size = st.size;
|
|
2034
|
+
if (st.size <= maxBytes) doc = parseYaml(readFileSync2(abs, "utf8"));
|
|
2035
|
+
}
|
|
1905
2036
|
} catch {
|
|
1906
2037
|
doc = null;
|
|
2038
|
+
size = void 0;
|
|
1907
2039
|
}
|
|
1908
|
-
this.cache.set(abs, doc);
|
|
2040
|
+
this.cache.set(abs, { doc, size });
|
|
1909
2041
|
return doc;
|
|
1910
2042
|
}
|
|
1911
2043
|
};
|
|
@@ -2035,7 +2167,7 @@ function walkPlaybooks(files, playbooks, opts) {
|
|
|
2035
2167
|
const rel = files.rel(abs);
|
|
2036
2168
|
for (const play of root.items) {
|
|
2037
2169
|
if (play.kind !== "map") continue;
|
|
2038
|
-
const imp =
|
|
2170
|
+
const imp = importPlaybookEntry(play);
|
|
2039
2171
|
if (imp) {
|
|
2040
2172
|
const target = scalarString(imp);
|
|
2041
2173
|
if (target && !isTemplated(target)) {
|
|
@@ -2116,6 +2248,53 @@ function walkFiles(dir, depth, out, base = dir) {
|
|
|
2116
2248
|
}
|
|
2117
2249
|
}
|
|
2118
2250
|
}
|
|
2251
|
+
var TREE_SKIP_DIRS = /* @__PURE__ */ new Set([".cache", ".git", ".hg", ".svn", ".tox"]);
|
|
2252
|
+
var TREE_MAX_ENTRIES = 2e5;
|
|
2253
|
+
function yamlFilesUnder(dir, maxEntries = TREE_MAX_ENTRIES) {
|
|
2254
|
+
const files = [];
|
|
2255
|
+
const realSeen = /* @__PURE__ */ new Set();
|
|
2256
|
+
let entriesSeen = 0;
|
|
2257
|
+
let incomplete;
|
|
2258
|
+
const walk = (d) => {
|
|
2259
|
+
if (incomplete) return;
|
|
2260
|
+
try {
|
|
2261
|
+
const real = realpathSync(d);
|
|
2262
|
+
if (realSeen.has(real)) return;
|
|
2263
|
+
realSeen.add(real);
|
|
2264
|
+
} catch {
|
|
2265
|
+
incomplete = `could not be fully listed (${d})`;
|
|
2266
|
+
return;
|
|
2267
|
+
}
|
|
2268
|
+
let entries;
|
|
2269
|
+
try {
|
|
2270
|
+
entries = readdirSync(d, { withFileTypes: true });
|
|
2271
|
+
} catch {
|
|
2272
|
+
incomplete = `could not be fully listed (${d})`;
|
|
2273
|
+
return;
|
|
2274
|
+
}
|
|
2275
|
+
for (const e of entries.sort((x, y) => x.name < y.name ? -1 : x.name > y.name ? 1 : 0)) {
|
|
2276
|
+
if (++entriesSeen > maxEntries) {
|
|
2277
|
+
incomplete = `has more than ${maxEntries} entries to pre-scan`;
|
|
2278
|
+
return;
|
|
2279
|
+
}
|
|
2280
|
+
const p = join2(d, e.name);
|
|
2281
|
+
let isDirEntry = e.isDirectory();
|
|
2282
|
+
let isFileEntry = e.isFile();
|
|
2283
|
+
if (e.isSymbolicLink()) {
|
|
2284
|
+
isDirEntry = isDir(p);
|
|
2285
|
+
isFileEntry = isFile(p);
|
|
2286
|
+
}
|
|
2287
|
+
if (isDirEntry) {
|
|
2288
|
+
if (!TREE_SKIP_DIRS.has(e.name)) walk(p);
|
|
2289
|
+
} else if (isFileEntry && /\.ya?ml$/i.test(e.name)) {
|
|
2290
|
+
files.push(p);
|
|
2291
|
+
}
|
|
2292
|
+
if (incomplete) return;
|
|
2293
|
+
}
|
|
2294
|
+
};
|
|
2295
|
+
walk(dir);
|
|
2296
|
+
return incomplete ? { files, incomplete } : { files };
|
|
2297
|
+
}
|
|
2119
2298
|
function readCfgStatic(dir) {
|
|
2120
2299
|
const p = join2(dir, "ansible.cfg");
|
|
2121
2300
|
if (!isFile(p)) return {};
|
|
@@ -2305,7 +2484,7 @@ function checkValue(label, spec, v, line, node, out) {
|
|
|
2305
2484
|
}
|
|
2306
2485
|
const choices = choicesOf(spec);
|
|
2307
2486
|
const elements = type === "list" ? spec.elements ?? null : null;
|
|
2308
|
-
const items =
|
|
2487
|
+
const items = type === "list" && Array.isArray(v) ? v : [v];
|
|
2309
2488
|
if (choices && (type !== "list" || Array.isArray(v) || typeof v !== "object")) {
|
|
2310
2489
|
const list = type === "list" && typeof v === "string" ? v.split(",").map((s) => s.trim()) : items;
|
|
2311
2490
|
for (const item of list) {
|
|
@@ -2313,7 +2492,7 @@ function checkValue(label, spec, v, line, node, out) {
|
|
|
2313
2492
|
if (choices.some((c) => c === item || String(c) === String(item))) continue;
|
|
2314
2493
|
if (typeof item === "boolean" && raw && isYaml11BoolWord(raw)) {
|
|
2315
2494
|
out.values.push(
|
|
2316
|
-
`${where}: unquoted ${raw} is the boolean ${item} in YAML 1.1, not one of ${choices.map(String).join("|")}; quote it ("${raw}")`
|
|
2495
|
+
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}")`
|
|
2317
2496
|
);
|
|
2318
2497
|
} else {
|
|
2319
2498
|
out.values.push(`${where}: ${show(item)} is not one of ${choices.map(String).join("|")}`);
|
|
@@ -2328,13 +2507,16 @@ function checkValue(label, spec, v, line, node, out) {
|
|
|
2328
2507
|
out.values.push(`${where}: expected ${type}, got ${err}${detail}`);
|
|
2329
2508
|
return;
|
|
2330
2509
|
}
|
|
2510
|
+
const hide = sensitive(label, spec, v);
|
|
2331
2511
|
if (type === "str" && typeof v === "boolean" && raw && isYaml11BoolWord(raw)) {
|
|
2332
2512
|
out.values.push(
|
|
2333
|
-
`${where}: unquoted ${raw} becomes the boolean ${v} in YAML 1.1 (Ansible passes the string '${v ? "True" : "False"}'); quote it ("${raw}")`
|
|
2513
|
+
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}")`
|
|
2334
2514
|
);
|
|
2335
2515
|
}
|
|
2336
2516
|
if (type === "str" && typeof v === "number" && /^0[0-7]+$/.test(raw)) {
|
|
2337
|
-
out.values.push(
|
|
2517
|
+
out.values.push(
|
|
2518
|
+
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}")`
|
|
2519
|
+
);
|
|
2338
2520
|
}
|
|
2339
2521
|
if (elements && Array.isArray(v)) {
|
|
2340
2522
|
const sub2 = subOptionsOf(spec);
|
|
@@ -3040,7 +3222,7 @@ function renderLint(version2, issues, stderr, maxLocations, profile) {
|
|
|
3040
3222
|
}
|
|
3041
3223
|
|
|
3042
3224
|
// src/playbook.ts
|
|
3043
|
-
import { readdirSync as readdirSync3 } from "fs";
|
|
3225
|
+
import { existsSync as existsSync4, readdirSync as readdirSync3 } from "fs";
|
|
3044
3226
|
import { dirname as dirname2, join as join4 } from "path";
|
|
3045
3227
|
var tagList = (s) => (s ?? "").replace(/^\[|\]$/g, "").split(",").map((x) => x.trim()).filter(Boolean);
|
|
3046
3228
|
function parseListOutput(text2) {
|
|
@@ -3119,35 +3301,51 @@ function firstSentence(text2) {
|
|
|
3119
3301
|
const i = text2.search(/\.\s+(?=[A-Z])/);
|
|
3120
3302
|
return (i > 0 ? text2.slice(0, i) : text2).replace(/\.$/, "");
|
|
3121
3303
|
}
|
|
3122
|
-
var LOOKUP_RE =
|
|
3304
|
+
var LOOKUP_RE = /\b(?:lookup|query|pipe)\b/;
|
|
3305
|
+
var Q_RE = /\bq\b/;
|
|
3306
|
+
function mentionsLookup(s) {
|
|
3307
|
+
if (LOOKUP_RE.test(s)) return true;
|
|
3308
|
+
const open = s.search(/\{[{%]/);
|
|
3309
|
+
return open >= 0 && Q_RE.test(s.slice(open));
|
|
3310
|
+
}
|
|
3311
|
+
var PRESCAN_MAX_BYTES = 32 * 1024 * 1024;
|
|
3123
3312
|
function prescanPlaybook(files, rel) {
|
|
3124
3313
|
const hits = [];
|
|
3125
3314
|
const seen = /* @__PURE__ */ new Set();
|
|
3126
3315
|
const visit = (abs) => {
|
|
3127
3316
|
if (seen.has(abs)) return;
|
|
3128
3317
|
seen.add(abs);
|
|
3129
|
-
const root = files.read(abs)?.root;
|
|
3130
|
-
if (root?.kind !== "seq") return;
|
|
3131
3318
|
const file = files.rel(abs);
|
|
3319
|
+
const doc = files.read(abs, PRESCAN_MAX_BYTES);
|
|
3320
|
+
if (!doc) {
|
|
3321
|
+
hits.push({ file, line: 0, play: "", field: "", unreadable: "could not be read" });
|
|
3322
|
+
return;
|
|
3323
|
+
}
|
|
3324
|
+
if (doc.errors.some((e) => e.startsWith(ALIAS_LIMIT_ERROR))) {
|
|
3325
|
+
hits.push({ file, line: 0, play: "", field: "", unreadable: `could not be fully parsed (${ALIAS_LIMIT_ERROR})` });
|
|
3326
|
+
return;
|
|
3327
|
+
}
|
|
3328
|
+
const root = doc.root;
|
|
3329
|
+
if (root?.kind !== "seq") return;
|
|
3132
3330
|
for (const play of root.items) {
|
|
3133
3331
|
if (play.kind !== "map") continue;
|
|
3134
3332
|
const nameNode = get(play, "name");
|
|
3135
3333
|
const label = nameNode?.kind === "scalar" && typeof nameNode.value === "string" ? nameNode.value : `#${play.line}`;
|
|
3136
3334
|
const check = (field, node) => {
|
|
3137
3335
|
for (const s of strings(node)) {
|
|
3138
|
-
if (
|
|
3336
|
+
if (mentionsLookup(s.value)) hits.push({ file, line: s.line, play: label, field });
|
|
3139
3337
|
}
|
|
3140
3338
|
};
|
|
3141
3339
|
check("name", nameNode);
|
|
3142
3340
|
check("hosts", get(play, "hosts"));
|
|
3143
3341
|
check("vars_files", get(play, "vars_files"));
|
|
3144
|
-
const imp =
|
|
3342
|
+
const imp = importPlaybookEntry(play);
|
|
3145
3343
|
if (imp) {
|
|
3146
3344
|
check("import_playbook", imp);
|
|
3147
3345
|
const target = imp.kind === "scalar" && typeof imp.value === "string" ? imp.value : null;
|
|
3148
3346
|
if (target && !isTemplated(target)) {
|
|
3149
3347
|
const p = join4(dirname2(abs), target);
|
|
3150
|
-
if (
|
|
3348
|
+
if (existsSync4(p)) visit(p);
|
|
3151
3349
|
}
|
|
3152
3350
|
}
|
|
3153
3351
|
}
|
|
@@ -3155,6 +3353,29 @@ function prescanPlaybook(files, rel) {
|
|
|
3155
3353
|
visit(files.abs(rel));
|
|
3156
3354
|
return hits;
|
|
3157
3355
|
}
|
|
3356
|
+
function prescanLintTargets(files, paths, maxEntries) {
|
|
3357
|
+
const hits = [];
|
|
3358
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3359
|
+
const scanFile = (abs) => {
|
|
3360
|
+
if (seen.has(abs)) return;
|
|
3361
|
+
seen.add(abs);
|
|
3362
|
+
const doc = files.read(abs, PRESCAN_MAX_BYTES);
|
|
3363
|
+
if (doc && !doc.errors.some((e) => e.startsWith(ALIAS_LIMIT_ERROR)) && !isPlaybookLike(doc.root)) return;
|
|
3364
|
+
hits.push(...prescanPlaybook(files, abs));
|
|
3365
|
+
};
|
|
3366
|
+
for (const p of paths) {
|
|
3367
|
+
if (isDir(p)) {
|
|
3368
|
+
const walk = yamlFilesUnder(p, maxEntries);
|
|
3369
|
+
if (walk.incomplete) {
|
|
3370
|
+
hits.push({ file: files.rel(p), line: 0, play: "", field: "", unreadable: walk.incomplete });
|
|
3371
|
+
}
|
|
3372
|
+
for (const abs of walk.files) scanFile(abs);
|
|
3373
|
+
} else if (existsSync4(p)) {
|
|
3374
|
+
scanFile(p);
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
return hits;
|
|
3378
|
+
}
|
|
3158
3379
|
function strings(node) {
|
|
3159
3380
|
if (!node) return [];
|
|
3160
3381
|
if (node.kind === "scalar") return typeof node.value === "string" ? [{ value: node.value, line: node.line }] : [];
|
|
@@ -3163,7 +3384,7 @@ function strings(node) {
|
|
|
3163
3384
|
}
|
|
3164
3385
|
function prescanRefusal(hits) {
|
|
3165
3386
|
const lines = hits.map(
|
|
3166
|
-
(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.`
|
|
3387
|
+
(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.`
|
|
3167
3388
|
);
|
|
3168
3389
|
lines.push("Set ANSIBLE_MCP_ALLOW_PLAY_LOOKUPS=1 to allow.");
|
|
3169
3390
|
return lines.join("\n");
|
|
@@ -3285,7 +3506,7 @@ function optionLines(opts, depth, descLen, defaults, warnings, ep, prefix) {
|
|
|
3285
3506
|
const flags = [];
|
|
3286
3507
|
if (o.required) flags.push("[required]");
|
|
3287
3508
|
if (o.default !== void 0 && o.default !== null)
|
|
3288
|
-
flags.push(o.no_log ? "[default: (no_log)]" : `[default: ${
|
|
3509
|
+
flags.push(o.no_log ? "[default: (no_log)]" : `[default: ${redactStandalone(o.default, name)}]`);
|
|
3289
3510
|
const ch = choicesOf(o);
|
|
3290
3511
|
if (ch) flags.push(`[choices: ${ch.map(String).join("|")}]`);
|
|
3291
3512
|
if (o.no_log) flags.push("[no_log]");
|
|
@@ -3325,13 +3546,16 @@ function renderRole(r) {
|
|
|
3325
3546
|
if (defaults) {
|
|
3326
3547
|
const noLog = /* @__PURE__ */ new Set();
|
|
3327
3548
|
const documented = /* @__PURE__ */ new Set();
|
|
3549
|
+
const red = new Redactor();
|
|
3328
3550
|
for (const e of Object.values(specs)) {
|
|
3329
3551
|
for (const [k, o] of Object.entries(e.options ?? {})) {
|
|
3330
3552
|
documented.add(k);
|
|
3331
3553
|
if (o.no_log) noLog.add(k);
|
|
3554
|
+
if (o.default === void 0 || o.default === null) continue;
|
|
3555
|
+
if (!o.no_log) red.learn(o.default, [k]);
|
|
3556
|
+
else if (typeof o.default === "string") red.addSecret(o.default);
|
|
3332
3557
|
}
|
|
3333
3558
|
}
|
|
3334
|
-
const red = new Redactor();
|
|
3335
3559
|
for (const [k, v] of Object.entries(defaults.values)) {
|
|
3336
3560
|
if (noLog.has(k)) {
|
|
3337
3561
|
if (typeof v === "string") red.addSecret(v);
|
|
@@ -3387,6 +3611,7 @@ function refuseDash(param, v) {
|
|
|
3387
3611
|
function assertRelative(ctx, p, rel, what) {
|
|
3388
3612
|
ctx.runner.assertLocal(rel);
|
|
3389
3613
|
refuseDash(what, rel);
|
|
3614
|
+
refuseDash(what, normalize(rel.trim()));
|
|
3390
3615
|
const abs = /^[A-Za-z]:[\\/]|^\//.test(rel) ? rel : join6(p.dir, rel);
|
|
3391
3616
|
ctx.runner.assertLocal(abs);
|
|
3392
3617
|
return abs;
|
|
@@ -3686,9 +3911,10 @@ async function roleInterface(ctx, x) {
|
|
|
3686
3911
|
let specs = null;
|
|
3687
3912
|
let source = "meta/argument_specs.yml";
|
|
3688
3913
|
if (ctx.runner.available()) {
|
|
3914
|
+
const base = roleDir.replace(/[\\/]+$/, "").split(/[\\/]/).pop();
|
|
3915
|
+
refuseDash("role", base);
|
|
3689
3916
|
try {
|
|
3690
3917
|
const sideParent = await ctx.runner.toSide(dirname3(roleDir));
|
|
3691
|
-
const base = roleDir.replace(/[\\/]+$/, "").split(/[\\/]/).pop();
|
|
3692
3918
|
const r = await ctx.runSafe(p, "ansible-doc", ["--json", "-t", "role", "-r", sideParent, base]);
|
|
3693
3919
|
if (r.code === 0) {
|
|
3694
3920
|
specs = roleSpecsFromDocJson(r.stdout, base)?.specs ?? null;
|
|
@@ -3755,11 +3981,6 @@ ${redactText(graph.stderr.trim()).slice(0, 2048)}`
|
|
|
3755
3981
|
for (const s of sources) bases.set(isDir(s) ? s : dirname3(s), "");
|
|
3756
3982
|
bases.set(p.dir, "");
|
|
3757
3983
|
const files = new ProjectFiles(p.dir);
|
|
3758
|
-
const fb = renderVarsFilesFallback(
|
|
3759
|
-
[...bases.keys()].map((b) => ({ base: b, label: files.rel(b) })),
|
|
3760
|
-
(abs) => files.rel(abs),
|
|
3761
|
-
red
|
|
3762
|
-
);
|
|
3763
3984
|
const env = { ANSIBLE_VARS_ENABLED: "none" };
|
|
3764
3985
|
const r = await ctx.runSafe(
|
|
3765
3986
|
p,
|
|
@@ -3769,23 +3990,32 @@ ${redactText(graph.stderr.trim()).slice(0, 2048)}`
|
|
|
3769
3990
|
env
|
|
3770
3991
|
}
|
|
3771
3992
|
);
|
|
3772
|
-
|
|
3773
|
-
`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.`
|
|
3774
|
-
];
|
|
3993
|
+
let hv = null;
|
|
3775
3994
|
if (r.code === 0) {
|
|
3776
3995
|
try {
|
|
3777
3996
|
const data = JSON.parse(r.stdout);
|
|
3778
|
-
|
|
3997
|
+
hv = host ? { [host]: data } : data?._meta?.hostvars ?? {};
|
|
3779
3998
|
learnAll(red, hv);
|
|
3780
|
-
out.push("inventory-file vars only:");
|
|
3781
|
-
for (const [h, vars] of Object.entries(hv)) {
|
|
3782
|
-
if (varsMode === "names") out.push(` ${h}: ${Object.keys(vars).sort().join(" ") || "(none)"}`);
|
|
3783
|
-
else {
|
|
3784
|
-
out.push(` ${h}:`);
|
|
3785
|
-
out.push(...renderHostVars(vars, red, " "));
|
|
3786
|
-
}
|
|
3787
|
-
}
|
|
3788
3999
|
} catch {
|
|
4000
|
+
hv = null;
|
|
4001
|
+
}
|
|
4002
|
+
}
|
|
4003
|
+
const fb = renderVarsFilesFallback(
|
|
4004
|
+
[...bases.keys()].map((b) => ({ base: b, label: files.rel(b) })),
|
|
4005
|
+
(abs) => files.rel(abs),
|
|
4006
|
+
red
|
|
4007
|
+
);
|
|
4008
|
+
const out = [
|
|
4009
|
+
`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.`
|
|
4010
|
+
];
|
|
4011
|
+
if (hv) {
|
|
4012
|
+
out.push("inventory-file vars only:");
|
|
4013
|
+
for (const [h, vars] of Object.entries(hv)) {
|
|
4014
|
+
if (varsMode === "names") out.push(` ${h}: ${Object.keys(vars).sort().join(" ") || "(none)"}`);
|
|
4015
|
+
else {
|
|
4016
|
+
out.push(` ${h}:`);
|
|
4017
|
+
out.push(...renderHostVars(vars, red, " "));
|
|
4018
|
+
}
|
|
3789
4019
|
}
|
|
3790
4020
|
}
|
|
3791
4021
|
out.push("group_vars / host_vars files:");
|
|
@@ -4023,15 +4253,24 @@ async function lintSummary(ctx, x) {
|
|
|
4023
4253
|
if (x.profile && !PROFILES.includes(x.profile)) return `profile must be one of ${PROFILES.join(", ")}`;
|
|
4024
4254
|
const p = await ctx.project(x.dir);
|
|
4025
4255
|
const files = new ProjectFiles(p.dir);
|
|
4026
|
-
const
|
|
4027
|
-
|
|
4028
|
-
return files.rel(abs);
|
|
4029
|
-
});
|
|
4030
|
-
const playbooks = targets.length ? targets.filter((t) => isPlaybookRoot(files.read(join6(p.dir, t))?.root ?? null)) : detectProject(p.dir).playbooks.map((pb) => pb.rel);
|
|
4031
|
-
const hits = playbooks.flatMap((pb) => prescanPlaybook(files, pb));
|
|
4256
|
+
const targetAbs = (x.paths ?? []).map((rel) => assertRelative(ctx, p, rel, "paths"));
|
|
4257
|
+
const hits = prescanLintTargets(files, targetAbs.length ? targetAbs : [p.dir]);
|
|
4032
4258
|
if (hits.length && !ctx.allowPlayLookups) return prescanRefusal(hits);
|
|
4033
4259
|
ctx.runner.assertAvailable();
|
|
4034
|
-
const
|
|
4260
|
+
const targets = [];
|
|
4261
|
+
for (const a of targetAbs) {
|
|
4262
|
+
const rel = files.rel(a);
|
|
4263
|
+
const target = rel === a.replace(/\\/g, "/") ? await ctx.runner.toSide(a) : rel;
|
|
4264
|
+
refuseDash("paths", target);
|
|
4265
|
+
targets.push(target);
|
|
4266
|
+
}
|
|
4267
|
+
const args = [
|
|
4268
|
+
"--offline",
|
|
4269
|
+
"-f",
|
|
4270
|
+
"codeclimate",
|
|
4271
|
+
...x.profile ? ["--profile", x.profile] : [],
|
|
4272
|
+
...targets.length ? ["--", ...targets] : []
|
|
4273
|
+
];
|
|
4035
4274
|
const [r, v] = await Promise.all([
|
|
4036
4275
|
ctx.runSafe(p, "ansible-lint", args),
|
|
4037
4276
|
ctx.quietEnv().then((env) => ctx.runner.run("ansible-lint", ["--version", "--offline"], { env })).catch(() => null)
|
|
@@ -4066,7 +4305,18 @@ function routingFor(rt, type, fqcn, collection) {
|
|
|
4066
4305
|
const short = fqcn.startsWith(`${collection}.`) ? fqcn.slice(collection.length + 1) : fqcn;
|
|
4067
4306
|
return t[short] ?? t[fqcn];
|
|
4068
4307
|
}
|
|
4069
|
-
|
|
4308
|
+
function fmtDefault(v, name, noLog) {
|
|
4309
|
+
if (noLog) return NO_LOG;
|
|
4310
|
+
const r = redactStandalone(v ?? null, name);
|
|
4311
|
+
if (r.startsWith('"')) {
|
|
4312
|
+
try {
|
|
4313
|
+
const s = JSON.parse(r);
|
|
4314
|
+
if (typeof s === "string") return `'${s}'`;
|
|
4315
|
+
} catch {
|
|
4316
|
+
}
|
|
4317
|
+
}
|
|
4318
|
+
return r;
|
|
4319
|
+
}
|
|
4070
4320
|
var fmtChoiceValue = (v) => typeof v === "string" ? v : JSON.stringify(v);
|
|
4071
4321
|
function sensitive2(label, spec, v) {
|
|
4072
4322
|
return spec.no_log === true || isSecretKey(label) || typeof v === "string" && hasSecretShape(v);
|
|
@@ -4148,7 +4398,12 @@ function diffOptions(inst, targ, args, prefix, push) {
|
|
|
4148
4398
|
const dI = specI.default ?? null;
|
|
4149
4399
|
const dT = specT.default ?? null;
|
|
4150
4400
|
if (JSON.stringify(dI) !== JSON.stringify(dT)) {
|
|
4151
|
-
|
|
4401
|
+
const noLog = specI.no_log === true || specT.no_log === true;
|
|
4402
|
+
push(
|
|
4403
|
+
"BEHAVIOR CHANGE",
|
|
4404
|
+
`${prefix}${name} not set; default ${fmtDefault(dI, name, noLog)} -> ${fmtDefault(dT, name, noLog)}`,
|
|
4405
|
+
7
|
|
4406
|
+
);
|
|
4152
4407
|
}
|
|
4153
4408
|
}
|
|
4154
4409
|
}
|
|
@@ -4208,7 +4463,7 @@ function renderUpgrade(r) {
|
|
|
4208
4463
|
lines.push(
|
|
4209
4464
|
`upgrade ${r.collection} ${r.installedVersion} -> ${r.targetVersion} (${bumpKind(r.installedVersion, r.targetVersion)}${down}) for ${r.dirLabel}`
|
|
4210
4465
|
);
|
|
4211
|
-
const req = r.requiresAnsible ? `requires_ansible '${r.requiresAnsible}' ${r.requiresOk ? "ok" : "NOT satisfied"} (ansible-core ${r.core})
|
|
4466
|
+
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})`;
|
|
4212
4467
|
lines.push(
|
|
4213
4468
|
`target: ${req}; dependencies: ${r.dependencies.length ? r.dependencies.join(", ") : "none"}; ${r.cacheNote}`
|
|
4214
4469
|
);
|
|
@@ -4264,6 +4519,8 @@ function renderUpgrade(r) {
|
|
|
4264
4519
|
else verdict = "NO IMPACT on used modules";
|
|
4265
4520
|
if (r.requiresAnsible && r.requiresOk === false) {
|
|
4266
4521
|
verdict = `BLOCKED (requires_ansible '${r.requiresAnsible}' excludes ansible-core ${r.core})${verdict.startsWith("BREAKING") ? `; also ${verdict}` : ""}`;
|
|
4522
|
+
} else if (r.requiresAnsible && r.requiresOk === void 0) {
|
|
4523
|
+
verdict += "; requires_ansible not checked";
|
|
4267
4524
|
}
|
|
4268
4525
|
lines.push(`verdict: ${verdict}`);
|
|
4269
4526
|
return lines.join("\n");
|
|
@@ -4352,6 +4609,7 @@ async function ensureTarget(ctx, p, collection, version2) {
|
|
|
4352
4609
|
if (hit && hit.collection_info?.version === version2) return { dir: target, downloaded: false, manifest: hit };
|
|
4353
4610
|
await ctx.runner.sideMkdirp(base);
|
|
4354
4611
|
const tmp = ctx.runner.sideJoin(base, `.tmp-${version2}-${randomBytes2(4).toString("hex")}`);
|
|
4612
|
+
let stale;
|
|
4355
4613
|
try {
|
|
4356
4614
|
const r = await ctx.runSafe(
|
|
4357
4615
|
p,
|
|
@@ -4369,16 +4627,22 @@ async function ensureTarget(ctx, p, collection, version2) {
|
|
|
4369
4627
|
if (!m || m.collection_info?.version !== version2) {
|
|
4370
4628
|
throw new Error(`ansible-galaxy installed ${collection} but MANIFEST.json does not say ${version2}.`);
|
|
4371
4629
|
}
|
|
4372
|
-
if (
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4630
|
+
if (await ctx.runner.sideRename(tmp, target)) return { dir: target, downloaded: true, manifest: m };
|
|
4631
|
+
const winner = await readManifest(ctx, target, collection);
|
|
4632
|
+
if (winner?.collection_info?.version === version2) return { dir: target, downloaded: true, manifest: winner };
|
|
4633
|
+
const aside = ctx.runner.sideJoin(base, `.tmp-stale-${randomBytes2(4).toString("hex")}`);
|
|
4634
|
+
if (await ctx.runner.sideRename(target, aside)) stale = aside;
|
|
4635
|
+
if (!stale || !await ctx.runner.sideRename(tmp, target)) {
|
|
4636
|
+
throw new Error(
|
|
4637
|
+
`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.`
|
|
4638
|
+
);
|
|
4377
4639
|
}
|
|
4378
4640
|
return { dir: target, downloaded: true, manifest: m };
|
|
4379
4641
|
} finally {
|
|
4380
4642
|
await ctx.runner.sideRemoveTemp(tmp, root).catch(() => {
|
|
4381
4643
|
});
|
|
4644
|
+
if (stale) await ctx.runner.sideRemoveTemp(stale, root).catch(() => {
|
|
4645
|
+
});
|
|
4382
4646
|
}
|
|
4383
4647
|
}
|
|
4384
4648
|
function sweepStaleTempDirs(cacheDir, now = Date.now()) {
|
|
@@ -4434,7 +4698,7 @@ async function runUpgrade(ctx, x) {
|
|
|
4434
4698
|
if (listRes.code !== 0)
|
|
4435
4699
|
throw new Error(
|
|
4436
4700
|
`ansible-galaxy collection list failed (exit ${listRes.code}):
|
|
4437
|
-
${listRes.stderr.trim().slice(0, 2048)}`
|
|
4701
|
+
${redactText(listRes.stderr.trim()).slice(0, 2048)}`
|
|
4438
4702
|
);
|
|
4439
4703
|
const installedAll = byCollection(parseCollectionList(listRes.stdout), collectionsPaths);
|
|
4440
4704
|
const eff = installedAll.get(collection)?.[0];
|
|
@@ -4557,11 +4821,13 @@ ${listRes.stderr.trim().slice(0, 2048)}`
|
|
|
4557
4821
|
}
|
|
4558
4822
|
);
|
|
4559
4823
|
let requiresOk;
|
|
4824
|
+
let requiresError;
|
|
4560
4825
|
if (targetRuntime.requiresAnsible) {
|
|
4561
4826
|
try {
|
|
4562
4827
|
requiresOk = satisfies(ver.core.replace(/[^\d.].*$/, ""), targetRuntime.requiresAnsible);
|
|
4563
|
-
} catch {
|
|
4828
|
+
} catch (e) {
|
|
4564
4829
|
requiresOk = void 0;
|
|
4830
|
+
requiresError = e instanceof Error ? e.message : String(e);
|
|
4565
4831
|
}
|
|
4566
4832
|
}
|
|
4567
4833
|
const reqFiles = det.requirements.map((f) => {
|
|
@@ -4608,7 +4874,7 @@ ${listRes.stderr.trim().slice(0, 2048)}`
|
|
|
4608
4874
|
targetVersion: version2,
|
|
4609
4875
|
dirLabel: p.dir,
|
|
4610
4876
|
core: ver.core,
|
|
4611
|
-
...targetRuntime.requiresAnsible ? { requiresAnsible: targetRuntime.requiresAnsible, requiresOk } : {},
|
|
4877
|
+
...targetRuntime.requiresAnsible ? { requiresAnsible: targetRuntime.requiresAnsible, requiresOk, ...requiresError ? { requiresError } : {} } : {},
|
|
4612
4878
|
dependencies: deps,
|
|
4613
4879
|
cacheNote,
|
|
4614
4880
|
constraints,
|