Add support for become in ansible playbook

Change-Id: Ia116f715042d4a4c8cc26ac45cf1a91be47435d3
This commit is contained in:
Michal Ovciarik 2020-02-25 10:24:38 +01:00
parent 497198a252
commit 45f2458584
6 changed files with 39 additions and 0 deletions

View File

@ -4460,6 +4460,11 @@ def ansible_playbook(parser, xml_parent, data):
XML.SubElement(plugin, "sudoUser").text = data.get("sudo-user", "")
else:
XML.SubElement(plugin, "sudo").text = "false"
if data.get("become", False):
XML.SubElement(plugin, "become").text = "true"
XML.SubElement(plugin, "becomeUser").text = data.get("become-user", "")
else:
XML.SubElement(plugin, "become").text = "false"
XML.SubElement(plugin, "forks").text = str(data.get("workers", "5"))
XML.SubElement(plugin, "unbufferedOutput").text = str(
data.get("unbuffered-output", True)

View File

@ -13,6 +13,7 @@
<credentialsId/>
<vaultCredentialsId/>
<sudo>false</sudo>
<become>false</become>
<forks>5</forks>
<unbufferedOutput>true</unbufferedOutput>
<colorizedOutput>false</colorizedOutput>

View File

@ -18,6 +18,7 @@ machine02.example.com
<vaultCredentialsId>0421b950-487b-4749-aa69-d87425e14459</vaultCredentialsId>
<sudo>true</sudo>
<sudoUser>cloud-user</sudoUser>
<become>false</become>
<forks>2</forks>
<unbufferedOutput>false</unbufferedOutput>
<colorizedOutput>true</colorizedOutput>

View File

@ -11,6 +11,7 @@
<credentialsId/>
<vaultCredentialsId/>
<sudo>false</sudo>
<become>false</become>
<forks>5</forks>
<unbufferedOutput>true</unbufferedOutput>
<colorizedOutput>false</colorizedOutput>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder>
<playbook>path/to/playbook.yml</playbook>
<inventory class="org.jenkinsci.plugins.ansible.InventoryDoNotSpecify"/>
<limit/>
<tags/>
<skippedTags/>
<startAtTask/>
<credentialsId/>
<vaultCredentialsId/>
<sudo>false</sudo>
<become>true</become>
<becomeUser>cloud-user</becomeUser>
<forks>5</forks>
<unbufferedOutput>true</unbufferedOutput>
<colorizedOutput>false</colorizedOutput>
<hostKeyChecking>false</hostKeyChecking>
<additionalParameters/>
<copyCredentialsInWorkspace>false</copyCredentialsInWorkspace>
</org.jenkinsci.plugins.ansible.AnsiblePlaybookBuilder>
</builders>
</project>

View File

@ -0,0 +1,7 @@
---
builders:
- ansible-playbook:
playbook: "path/to/playbook.yml"
inventory-type: "do-not-specify"
become: "yes"
become-user: "cloud-user"