remove hosts, change run without shell cmd
This commit is contained in:
parent
f32cc1b6a0
commit
bfad48fff1
41
ansible/Jenkinsfile
vendored
41
ansible/Jenkinsfile
vendored
@ -27,20 +27,7 @@ pipeline {
|
||||
ansible-vault decrypt ./ansible/id_ed25519_vault --output=${decryptedKeyFile} --vault-password-file=${vaultPassFile}
|
||||
"""
|
||||
|
||||
def hostsFile = "${tempDir}/hosts.ini"
|
||||
def hostsFileContent = """
|
||||
[SiteA]
|
||||
192.168.0.61 ansible_user=ansible ansible_ssh_private_key_file=${decryptedKeyFile}
|
||||
|
||||
[SiteB]
|
||||
192.168.0.62 ansible_user=ansible ansible_ssh_private_key_file=${decryptedKeyFile}
|
||||
|
||||
[proxy]
|
||||
192.168.0.63 ansible_user=ansible ansible_ssh_private_key_file=${decryptedKeyFile}
|
||||
"""
|
||||
writeFile file: hostsFile, text: hostsFileContent
|
||||
|
||||
env.HOSTS_FILE = hostsFile
|
||||
env.DECYPTED_KEY_FILE = decryptedKeyFile
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -50,13 +37,27 @@ pipeline {
|
||||
script {
|
||||
def sanitized_content = params.ADDITIONAL_CONTENT.replaceAll("'", "\\'").replaceAll('"', '\\"')
|
||||
|
||||
if (params.SITE_OPTION == 'SiteA') {
|
||||
sh "export PATH=/usr/local/bin:\$PATH && ansible-playbook /coursework/ansible/playbook.ymlansible/playbook.yml -i ${env.HOSTS_FILE} -l SiteA -e \"additional_content='${sanitized_content}'\""
|
||||
} else if (params.SITE_OPTION == 'SiteB') {
|
||||
sh "export PATH=/usr/local/bin:\$PATH && ansible-playbook /coursework/ansible/playbook.ymlansible/playbook.yml -i ${env.HOSTS_FILE} -l SiteB -e \"additional_content='${sanitized_content}'\""
|
||||
} else if (params.SITE_OPTION == 'SiteA&B') {
|
||||
sh "export PATH=/usr/local/bin:\$PATH && ansible-playbook /coursework/ansible/playbook.yml -i ${env.HOSTS_FILE} -l SiteA,SiteB,proxy -e \"additional_content='${sanitized_content}'\""
|
||||
def siteOption = params.SITE_OPTION
|
||||
def hostsFile = env.HOSTS_FILE
|
||||
|
||||
def targetGroups = ''
|
||||
if (siteOption == 'SiteA') {
|
||||
targetGroups = 'SiteA'
|
||||
} else if (siteOption == 'SiteB') {
|
||||
targetGroups = 'SiteB'
|
||||
} else if (siteOption == 'SiteA&B') {
|
||||
targetGroups = 'SiteA,SiteB,proxy'
|
||||
}
|
||||
|
||||
ansiblePlaybook(
|
||||
playbook: 'ansible/playbook.yml',
|
||||
inventory: "ansible/inventory.yml",
|
||||
extraVars: [
|
||||
additional_content: sanitized_content,
|
||||
ansible_ssh_private_key_file: env.DECYPTED_KEY_FILE
|
||||
],
|
||||
limit: targetGroups
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
[SiteA]
|
||||
192.168.0.61 ansible_user=ansible
|
||||
[SiteB]
|
||||
192.168.0.62 ansible_user=ansible
|
||||
[proxy]
|
||||
192.168.0.63 ansible_user=ansible
|
14
ansible/inventory.yml
Normal file
14
ansible/inventory.yml
Normal file
@ -0,0 +1,14 @@
|
||||
all:
|
||||
children:
|
||||
SiteA:
|
||||
hosts:
|
||||
192.168.0.61:
|
||||
ansible_user: ansible
|
||||
SiteB:
|
||||
hosts:
|
||||
192.168.0.62:
|
||||
ansible_user: ansible
|
||||
proxy:
|
||||
hosts:
|
||||
192.168.0.63:
|
||||
ansible_user: ansible
|
Loading…
Reference in New Issue
Block a user