Last active
August 13, 2021 00:08
-
-
Save nathan815/8e8f537a88658c6bb4c0d5f5046fae10 to your computer and use it in GitHub Desktop.
AWX auto-fill survey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:function fillSurveyField(e){const n=angular.element("#"+e).scope(),i=n.$parent.$parent.promptData,o=n.question.variable,t=i.prompts.variables.value.split("\n"),l=t&&t.find(e=>e.includes(o));if(!l)return void console.log(`No value for ${o} found in extra vars`);const r=i.surveyQuestions.find(e=>e.variable==o),a=("integer"==r.type?e=>parseInt(e):e=>e)(l.split(":")[1].trim());console.log(`Changing value of input ${o} to ${a}`),r.model=a}for(const e of $('input[id^="survey_question_"]'))fillSurveyField(e.id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unmnified code | |
function fillSurveyField(id) { | |
const input = angular.element('#' + id); | |
const scope = input.scope(); | |
const promptData = scope.$parent.$parent.promptData; | |
const varName = scope.question.variable; | |
const vars = promptData.prompts.variables.value.split('\n'); | |
const varValue = vars && vars.find(str => str.includes(varName)); | |
if (!varValue) { | |
console.log(`No value for ${varName} found in extra vars`); | |
return; | |
} | |
const questionObj = promptData.surveyQuestions.find(q => q.variable == varName); | |
const transform = questionObj.type == 'integer' ? (v) => parseInt(v) : (v) => v; | |
const newValue = transform(varValue.split(':')[1].trim()); | |
console.log(`Changing value of input ${varName} to ${newValue}`); | |
questionObj.model = newValue; | |
} | |
for (const input of $('input[id^="survey_question_"]')) { | |
fillSurveyField(input.id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This bookmarklet will autofill all the survey fields in an AWX Launch Job Prompt in one click. It gets the values from the extra vars which are much easier to paste or edit. | |
Just add the `javascript:...` code as the URL in a bookmark. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment