successful windows ansible run
This commit is contained in:
5
ansible.cfg
Normal file
5
ansible.cfg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[defaults]
|
||||||
|
|
||||||
|
roles_path = /var/jenkins_home/ansible-windows/roles
|
||||||
|
|
||||||
|
ansible_root = /var/jenkins_home/ansible-windows
|
||||||
@ -120,16 +120,27 @@ for IP in "${IPS[@]}"; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
inventory_content+=" vars:
|
inventory_content+=" vars:
|
||||||
|
# windows user info
|
||||||
ansible_user: ${WINDOWS_USER}
|
ansible_user: ${WINDOWS_USER}
|
||||||
ansible_password: '${ANSIBLE_PASSWORD}'
|
ansible_password: '${ANSIBLE_PASSWORD}'
|
||||||
|
ansible_become_user: ${WINDOWS_USER}
|
||||||
|
ansible_become_pass: '${ANSIBLE_PASSWORD}'
|
||||||
|
|
||||||
|
# ansible connection info
|
||||||
ansible_connection: winrm
|
ansible_connection: winrm
|
||||||
|
ansible_winrm_transport: basic
|
||||||
ansible_winrm_server_cert_validation: ignore
|
ansible_winrm_server_cert_validation: ignore
|
||||||
winrm_transport = ntlm
|
ansible_winrm_scheme: http
|
||||||
ansible_python_interpreter: /usr/bin/python3
|
ansible_winrm_port: 5985
|
||||||
|
|
||||||
|
# jenkins user info
|
||||||
jenkins_user: '${JENKINS_USER}'
|
jenkins_user: '${JENKINS_USER}'
|
||||||
jenkins_group: '${JENKINS_GROUP}'
|
jenkins_group: '${JENKINS_GROUP}'
|
||||||
subnet_group_check: '${allsubnet_group}'
|
subnet_group_check: '${allsubnet_group}'
|
||||||
SERVER_SUBNET_GROUP: '${SERVER_SUBNET_GROUP}'
|
SERVER_SUBNET_GROUP: '${SERVER_SUBNET_GROUP}'
|
||||||
|
|
||||||
|
# other variables
|
||||||
|
ansible_python_interpreter: /usr/bin/python3
|
||||||
"
|
"
|
||||||
|
|
||||||
# Write the inventory content to the file
|
# Write the inventory content to the file
|
||||||
|
|||||||
@ -22,6 +22,26 @@ pipeline {
|
|||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
|
||||||
|
stage('Powershell Test'){
|
||||||
|
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
def remoteHost = '${params.host_ip}'
|
||||||
|
def powershellScript = '''
|
||||||
|
$username = "${env:ansible_service_windows_USR}"
|
||||||
|
$password = "${env:ansible_service_windows_PSW}"
|
||||||
|
Write-Host "Using username: $username and password: $password"
|
||||||
|
'''
|
||||||
|
|
||||||
|
bat """
|
||||||
|
echo Running PowerShell script on remote machine...
|
||||||
|
cmd /c powershell -Command "& { ${powershellScript} }"
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
stage('Generate Inventory File') {
|
stage('Generate Inventory File') {
|
||||||
steps {
|
steps {
|
||||||
|
|
||||||
|
|||||||
@ -3,10 +3,10 @@
|
|||||||
- name: Ansible Test
|
- name: Ansible Test
|
||||||
hosts: all
|
hosts: all
|
||||||
become: yes
|
become: yes
|
||||||
|
become_method: runas
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
|
|
||||||
- show_user_vars
|
- show_user_vars
|
||||||
|
|
||||||
- display_hostname
|
- display_hostname
|
||||||
|
|||||||
@ -1,15 +1,12 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
|
- name: Check hostname
|
||||||
tasks:
|
ansible.windows.win_command: hostname
|
||||||
|
register: hostname_output
|
||||||
- name: Show some information
|
|
||||||
become: true
|
|
||||||
ansible.windows.win_command: |
|
|
||||||
hostname
|
|
||||||
whoami
|
|
||||||
gpresult /v | find "DC=cosmos"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
- name: display hostname
|
||||||
|
debug:
|
||||||
|
msg: "Hostname: {{ hostname_output.stdout_lines[0] }}"
|
||||||
|
|
||||||
...
|
...
|
||||||
Reference in New Issue
Block a user