Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add job options to ansible env #358

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
> [!TIP]
> This fork main purpose is to forward the RUNDECK variables (such as RD_JOB_USERNAME, etc.) to the Ansible playbook. One reason is to give the ansible playbook the ability to proper identify who is running the playbook.

---

[![Gitter](https://img.shields.io/gitter/room/rundeck-ansible-plugin/Lobby.svg)](https://gitter.im/rundeck-ansible-plugin/Lobby) [Read more about Rundeck + Ansible](https://www.rundeck.com/ansible)

Please [report](https://github.com/rundeck-plugins/ansible-plugin/issues) any errors or suggestions!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public static AnsibleRunner buildAnsibleRunner(AnsibleRunnerContextBuilder conte
// set rundeck options as environment variables
Map<String,String> options = contextBuilder.getListOptions();
if (options != null) {
//also add all the job options
options.putAll(contextBuilder.getJobOptions());
ansibleRunnerBuilder.options(options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,4 +833,15 @@ public Map<String,String> getListOptions(){
}
return options;
}

public Map<String,String> getJobOptions(){
Map<String, String> options = new HashMap<>();
Map<String, String> jobOptions = context.getDataContext().get("job");
for (Map.Entry<String, String> entry : jobOptions.entrySet()) {
if(entry.getValue() != null) {
options.put("RD_JOB_" + entry.getKey().toUpperCase(), entry.getValue());
}
}
return options;
}
}