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

Feat ansible #277

Open
wants to merge 8 commits into
base: master
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
_NOTES*
go-convert
convert/circle/reference/**
.idea/
.idea/
.codegpt
9 changes: 9 additions & 0 deletions convert/jenkinsjson/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,15 @@ func collectStepsWithID(currentNode jenkinsjson.Node, stepGroupWithId *[]StepGro
case "unarchive":
*stepWithIDList = append(*stepWithIDList, StepWithID{Step: jenkinsjson.ConvertUnarchive(currentNode, currentNode.ParameterMap), ID: id})

case "ansiblePlaybook":
*stepWithIDList = append(*stepWithIDList, StepWithID{Step: jenkinsjson.ConvertAnsiblePlaybook(currentNode, currentNode.ParameterMap), ID: id})

case "ansibleVault":
*stepWithIDList = append(*stepWithIDList, StepWithID{Step: jenkinsjson.ConvertAnsibleVault(currentNode, currentNode.ParameterMap), ID: id})

case "ansibleAdhoc":
*stepWithIDList = append(*stepWithIDList, StepWithID{Step: jenkinsjson.ConvertAnsibleAdhoc(currentNode, currentNode.ParameterMap), ID: id})

case "waitForQualityGate":
*stepWithIDList = append(*stepWithIDList, StepWithID{Step: jenkinsjson.ConvertSonarQualityGate(currentNode), ID: id})

Expand Down
104 changes: 104 additions & 0 deletions convert/jenkinsjson/convertTestFiles/ansible/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
pipeline {
agent any
stages {
stage('Setup Inline Playbook and Inventory') {
steps {
script {
// Write the inline playbook
writeFile file: 'playbook.yml', text: '''
---
- hosts: all
tasks:
- name: Ping all hosts
ping:
- name: Show debug message
debug:
msg: "This is a simple test of the Ansible Playbook plugin in Jenkins"
'''

// Write the inline inventory
writeFile file: 'inventory', text: '''
[all]
localhost ansible_connection=local
'''
}
}
}
stage('Run Ansible Playbook') {
steps {
ansiblePlaybook(
playbook: 'playbook.yml',
inventory: 'inventory',
colorized: true,
become: false,
becomeUser: 'root',
checkMode: false,
credentialsId: '',
disableHostKeyChecking: true,
dynamicInventory: false,
extraVars: [custom_var1: 'value1', custom_var2: 'value2'],
extras: '--timeout=30',
forks: 5,
hostKeyChecking: false,
installation: '',
limit: '',
skippedTags: '',
startAtTask: '',
sudo: false,
sudoUser: '',
tags: '',
vaultCredentialsId: '',
vaultTmpPath: '/tmp'
)
}
}
stage('Run Ansible Ad-Hoc Command') {
steps {
ansibleAdhoc(
hosts: 'all',
become: false,
becomeUser: 'root',
colorized: true,
credentialsId: '',
dynamicInventory: false,
extraVars: [
[key: 'custom_var1', value: 'value1'],
[key: 'custom_var2', value: 'value2']
],
extras: '--timeout=30',
forks: 5,
hostKeyChecking: false,
installation: '',
inventory: 'inventory',
inventoryContent: '[all]\nlocalhost ansible_connection=local',
module: 'ping',
moduleArguments: '',
vaultCredentialsId: '',
vaultTmpPath: '/tmp'
)
}
}
stage('Test Ansible Vault Plugin') {
steps {
script {
writeFile file: 'test_vault.txt', text: 'Testing Ansible Vault Plugin functionality.'

ansibleVault(
action: 'encrypt',
input: 'test_vault.txt',
vaultCredentialsId: 'test-vault-id',
vaultTmpPath: '/tmp'
)

echo "Encryption completed successfully."
}
}
}
}
post {
always {
echo 'Cleaning up temporary files'
sh 'rm -f playbook.yml inventory sample.txt sample.txt.enc sample_decrypted.txt'
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- step:
identifier: ansibleadhoc4eb052
name: Ansible_Adhoc
spec:
image: plugins/ansible
settings:
become: "false"
become_user: root
dynamic_inventory: "false"
extra_vars: ""
extras: --timeout=30
forks: "5"
host_key_checking: "false"
hosts: all
installation: ""
inventory: inventory
inventory_content: |-
[all]
localhost ansible_connection=local
mode: adhoc
module: ping
module_args: ""
private_key: ""
vault_credentials_key: ""
vault_tmp_path: /tmp
timeout: ""
type: Plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"spanId": "4eb052213ca082c4",
"traceId": "7f0304d2ba6fa0aaae5d71cc94b3cdfa",
"parent": "vani_ansible_test",
"all-info": "span(name: ansibleAdhoc, spanId: 4eb052213ca082c4, parentSpanId: 8066bc0151e6b1a9, traceId: 7f0304d2ba6fa0aaae5d71cc94b3cdfa, attr: ci.pipeline.run.user:SYSTEM;harness-attribute:{\n \"forks\" : 5,\n \"hostKeyChecking\" : false,\n \"moduleArguments\" : \"\",\n \"hosts\" : \"all\",\n \"dynamicInventory\" : false,\n \"module\" : \"ping\",\n \"extras\" : \"--timeout=30\",\n \"credentialsId\" : \"\",\n \"inventory\" : \"inventory\",\n \"becomeUser\" : \"root\",\n \"colorized\" : true,\n \"inventoryContent\" : \"[all]\\nlocalhost ansible_connection=local\",\n \"vaultCredentialsId\" : \"\",\n \"installation\" : \"\",\n \"vaultTmpPath\" : \"/tmp\",\n \"extraVars\" : [ {\n \"key\" : \"custom_var1\",\n \"value\" : \"value1\"\n }, {\n \"key\" : \"custom_var2\",\n \"value\" : \"value2\"\n } ],\n \"become\" : false\n};harness-attribute-extra-pip: com.cloudbees.workflow.rest.endpoints.FlowNodeAPI@3e51500e:com.cloudbees.workflow.rest.endpoints.FlowNodeAPI@3e51500e;harness-attribute-extra-pip: io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@53198870:io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@53198870;harness-attribute-extra-pip: org.jenkinsci.plugins.workflow.actions.TimingAction@75f30ace:org.jenkinsci.plugins.workflow.actions.TimingAction@75f30ace;harness-others:;jenkins.pipeline.step.id:22;jenkins.pipeline.step.name:Invoke an ansible adhoc command;jenkins.pipeline.step.plugin.name:ansible;jenkins.pipeline.step.plugin.version:403.v8d0ca_dcb_b_502;jenkins.pipeline.step.type:ansibleAdhoc;)",
"name": "vani_ansible_test #25",
"attributesMap": {
"harness-attribute-extra-pip: com.cloudbees.workflow.rest.endpoints.FlowNodeAPI@3e51500e": "com.cloudbees.workflow.rest.endpoints.FlowNodeAPI@3e51500e",
"harness-others": "",
"jenkins.pipeline.step.name": "Invoke an ansible adhoc command",
"ci.pipeline.run.user": "SYSTEM",
"jenkins.pipeline.step.id": "22",
"jenkins.pipeline.step.type": "ansibleAdhoc",
"harness-attribute": "{\n \"forks\" : 5,\n \"hostKeyChecking\" : false,\n \"moduleArguments\" : \"\",\n \"hosts\" : \"all\",\n \"dynamicInventory\" : false,\n \"module\" : \"ping\",\n \"extras\" : \"--timeout=30\",\n \"credentialsId\" : \"\",\n \"inventory\" : \"inventory\",\n \"becomeUser\" : \"root\",\n \"colorized\" : true,\n \"inventoryContent\" : \"[all]\\nlocalhost ansible_connection=local\",\n \"vaultCredentialsId\" : \"\",\n \"installation\" : \"\",\n \"vaultTmpPath\" : \"/tmp\",\n \"extraVars\" : [ {\n \"key\" : \"custom_var1\",\n \"value\" : \"value1\"\n }, {\n \"key\" : \"custom_var2\",\n \"value\" : \"value2\"\n } ],\n \"become\" : false\n}",
"harness-attribute-extra-pip: org.jenkinsci.plugins.workflow.actions.TimingAction@75f30ace": "org.jenkinsci.plugins.workflow.actions.TimingAction@75f30ace",
"jenkins.pipeline.step.plugin.name": "ansible",
"jenkins.pipeline.step.plugin.version": "403.v8d0ca_dcb_b_502",
"harness-attribute-extra-pip: io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@53198870": "io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@53198870"
},
"type": "Run Phase Span",
"parentSpanId": "8066bc0151e6b1a9",
"parameterMap": {
"forks": 5,
"hostKeyChecking": false,
"moduleArguments": "",
"hosts": "all",
"dynamicInventory": false,
"module": "ping",
"extras": "--timeout=30",
"credentialsId": "",
"inventory": "inventory",
"becomeUser": "root",
"colorized": true,
"inventoryContent": "[all]\nlocalhost ansible_connection=local",
"vaultCredentialsId": "",
"installation": "",
"vaultTmpPath": "/tmp",
"extraVars": [
{
"value": "value1",
"key": "custom_var1"
},
{
"value": "value2",
"key": "custom_var2"
}
],
"become": false
},
"spanName": "ansibleAdhoc"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
- step:
identifier: ansibleplaybookb8e0a2
name: Ansible_Playbook
spec:
image: plugins/ansible
settings:
become: "false"
become_user: root
check: "false"
disable_host_key_checking: "true"
dynamic_inventory: "false"
extra_vars: ""
extras: --timeout=30
forks: "5"
host_key_checking: "false"
installation: ""
inventory: inventory
inventory_content: ""
limit: ""
mode: playbook
playbook: playbook.yml
private_key: ""
skip_tags: ""
start_at_task: ""
sudo: "false"
sudo_user: ""
tags: ""
vault_id: ""
vault_tmp_path: /tmp
timeout: ""
type: Plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"spanId": "b8e0a2f7c38f1346",
"traceId": "7f0304d2ba6fa0aaae5d71cc94b3cdfa",
"parent": "vani_ansible_test",
"all-info": "span(name: ansiblePlaybook, spanId: b8e0a2f7c38f1346, parentSpanId: 4d5eafacc3be8901, traceId: 7f0304d2ba6fa0aaae5d71cc94b3cdfa, attr: ci.pipeline.run.user:SYSTEM;harness-attribute:{\n \"forks\" : 5,\n \"hostKeyChecking\" : false,\n \"disableHostKeyChecking\" : true,\n \"startAtTask\" : \"\",\n \"dynamicInventory\" : false,\n \"extras\" : \"--timeout=30\",\n \"credentialsId\" : \"\",\n \"inventory\" : \"inventory\",\n \"colorized\" : true,\n \"becomeUser\" : \"root\",\n \"tags\" : \"\",\n \"sudoUser\" : \"\",\n \"vaultCredentialsId\" : \"\",\n \"checkMode\" : false,\n \"skippedTags\" : \"\",\n \"installation\" : \"\",\n \"vaultTmpPath\" : \"/tmp\",\n \"limit\" : \"\",\n \"extraVars\" : {\n \"custom_var1\" : \"value1\",\n \"custom_var2\" : \"value2\"\n },\n \"sudo\" : false,\n \"playbook\" : \"playbook.yml\",\n \"become\" : false\n};harness-attribute-extra-pip: com.cloudbees.workflow.rest.endpoints.FlowNodeAPI@55c0f06d:com.cloudbees.workflow.rest.endpoints.FlowNodeAPI@55c0f06d;harness-attribute-extra-pip: io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@17e25555:io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@17e25555;harness-attribute-extra-pip: org.jenkinsci.plugins.workflow.actions.TimingAction@335e37cf:org.jenkinsci.plugins.workflow.actions.TimingAction@335e37cf;harness-others:;jenkins.pipeline.step.id:17;jenkins.pipeline.step.name:Invoke an ansible playbook;jenkins.pipeline.step.plugin.name:ansible;jenkins.pipeline.step.plugin.version:403.v8d0ca_dcb_b_502;jenkins.pipeline.step.type:ansiblePlaybook;)",
"name": "vani_ansible_test #25",
"attributesMap": {
"harness-attribute-extra-pip: io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@17e25555": "io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@17e25555",
"harness-others": "",
"jenkins.pipeline.step.name": "Invoke an ansible playbook",
"ci.pipeline.run.user": "SYSTEM",
"jenkins.pipeline.step.id": "17",
"jenkins.pipeline.step.type": "ansiblePlaybook",
"harness-attribute": "{\n \"forks\" : 5,\n \"hostKeyChecking\" : false,\n \"disableHostKeyChecking\" : true,\n \"startAtTask\" : \"\",\n \"dynamicInventory\" : false,\n \"extras\" : \"--timeout=30\",\n \"credentialsId\" : \"\",\n \"inventory\" : \"inventory\",\n \"colorized\" : true,\n \"becomeUser\" : \"root\",\n \"tags\" : \"\",\n \"sudoUser\" : \"\",\n \"vaultCredentialsId\" : \"\",\n \"checkMode\" : false,\n \"skippedTags\" : \"\",\n \"installation\" : \"\",\n \"vaultTmpPath\" : \"/tmp\",\n \"limit\" : \"\",\n \"extraVars\" : {\n \"custom_var1\" : \"value1\",\n \"custom_var2\" : \"value2\"\n },\n \"sudo\" : false,\n \"playbook\" : \"playbook.yml\",\n \"become\" : false\n}",
"harness-attribute-extra-pip: com.cloudbees.workflow.rest.endpoints.FlowNodeAPI@55c0f06d": "com.cloudbees.workflow.rest.endpoints.FlowNodeAPI@55c0f06d",
"harness-attribute-extra-pip: org.jenkinsci.plugins.workflow.actions.TimingAction@335e37cf": "org.jenkinsci.plugins.workflow.actions.TimingAction@335e37cf",
"jenkins.pipeline.step.plugin.name": "ansible",
"jenkins.pipeline.step.plugin.version": "403.v8d0ca_dcb_b_502"
},
"type": "Run Phase Span",
"parentSpanId": "4d5eafacc3be8901",
"parameterMap": {
"forks": 5,
"hostKeyChecking": false,
"disableHostKeyChecking": true,
"startAtTask": "",
"dynamicInventory": false,
"extras": "--timeout=30",
"credentialsId": "",
"inventory": "inventory",
"colorized": true,
"becomeUser": "root",
"tags": "",
"sudoUser": "",
"vaultCredentialsId": "",
"checkMode": false,
"skippedTags": "",
"installation": "",
"vaultTmpPath": "/tmp",
"limit": "",
"extraVars": {
"custom_var2": "value2",
"custom_var1": "value1"
},
"sudo": false,
"playbook": "playbook.yml",
"become": false
},
"spanName": "ansiblePlaybook"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- step:
identifier: ansiblevault60a60b
name: Ansible_Vault
spec:
image: plugins/ansible
settings:
action: encrypt
content: ""
input: content_to_encrypt.txt
installation: ""
mode: vault
output: encrypted_content.txt
vault_credentials_key: test-vault-id
vault_tmp_path: /tmp
timeout: ""
type: Plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"spanId": "60a60b177ce71179",
"traceId": "7f0304d2ba6fa0aaae5d71cc94b3cdfa",
"parent": "vani_ansible_test",
"all-info": "span(name: ansibleVault, spanId: 60a60b177ce71179, parentSpanId: 43a7cba65433cdbc, traceId: 7f0304d2ba6fa0aaae5d71cc94b3cdfa, attr: ci.pipeline.run.user:SYSTEM;harness-attribute:{\n \"output\" : \"encrypted_content.txt\",\n \"action\" : \"encrypt\",\n \"input\" : \"content_to_encrypt.txt\",\n \"vaultCredentialsId\" : \"test-vault-id\",\n \"vaultTmpPath\" : \"/tmp\"\n};harness-attribute-extra-pip: com.cloudbees.workflow.rest.endpoints.FlowNodeAPI@5ee5a554:com.cloudbees.workflow.rest.endpoints.FlowNodeAPI@5ee5a554;harness-attribute-extra-pip: io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@33637909:io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@33637909;harness-attribute-extra-pip: org.jenkinsci.plugins.workflow.actions.TimingAction@3b4ac42d:org.jenkinsci.plugins.workflow.actions.TimingAction@3b4ac42d;harness-others:;jenkins.pipeline.step.id:30;jenkins.pipeline.step.name:Invoke ansible vault;jenkins.pipeline.step.plugin.name:ansible;jenkins.pipeline.step.plugin.version:403.v8d0ca_dcb_b_502;jenkins.pipeline.step.type:ansibleVault;)",
"name": "vani_ansible_test #25",
"attributesMap": {
"harness-attribute-extra-pip: io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@33637909": "io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@33637909",
"harness-attribute-extra-pip: com.cloudbees.workflow.rest.endpoints.FlowNodeAPI@5ee5a554": "com.cloudbees.workflow.rest.endpoints.FlowNodeAPI@5ee5a554",
"harness-others": "",
"jenkins.pipeline.step.name": "Invoke ansible vault",
"ci.pipeline.run.user": "SYSTEM",
"jenkins.pipeline.step.id": "30",
"jenkins.pipeline.step.type": "ansibleVault",
"harness-attribute": "{\n \"output\" : \"encrypted_content.txt\",\n \"action\" : \"encrypt\",\n \"input\" : \"content_to_encrypt.txt\",\n \"vaultCredentialsId\" : \"test-vault-id\",\n \"vaultTmpPath\" : \"/tmp\"\n}",
"jenkins.pipeline.step.plugin.name": "ansible",
"harness-attribute-extra-pip: org.jenkinsci.plugins.workflow.actions.TimingAction@3b4ac42d": "org.jenkinsci.plugins.workflow.actions.TimingAction@3b4ac42d",
"jenkins.pipeline.step.plugin.version": "403.v8d0ca_dcb_b_502"
},
"type": "Run Phase Span",
"parentSpanId": "43a7cba65433cdbc",
"parameterMap": {
"output": "encrypted_content.txt",
"input": "content_to_encrypt.txt",
"vaultCredentialsId": "test-vault-id",
"vaultTmpPath": "/tmp",
"action": "encrypt"
},
"spanName": "ansibleVault"
}
Loading