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}
|
ansible-vault decrypt ./ansible/id_ed25519_vault --output=${decryptedKeyFile} --vault-password-file=${vaultPassFile}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def hostsFile = "${tempDir}/hosts.ini"
|
env.DECYPTED_KEY_FILE = decryptedKeyFile
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,13 +37,27 @@ pipeline {
|
|||||||
script {
|
script {
|
||||||
def sanitized_content = params.ADDITIONAL_CONTENT.replaceAll("'", "\\'").replaceAll('"', '\\"')
|
def sanitized_content = params.ADDITIONAL_CONTENT.replaceAll("'", "\\'").replaceAll('"', '\\"')
|
||||||
|
|
||||||
if (params.SITE_OPTION == 'SiteA') {
|
def siteOption = params.SITE_OPTION
|
||||||
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}'\""
|
def hostsFile = env.HOSTS_FILE
|
||||||
} 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}'\""
|
def targetGroups = ''
|
||||||
} else if (params.SITE_OPTION == 'SiteA&B') {
|
if (siteOption == 'SiteA') {
|
||||||
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}'\""
|
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