Skip to content

Instantly share code, notes, and snippets.

View virtualhobbit's full-sized avatar
:octocat:
Building clouds

Mark Brookfield virtualhobbit

:octocat:
Building clouds
View GitHub Profile
resources:
Cloud_Ansible_Tower_1:
type: Cloud.Ansible.Tower
metadata:
layoutPosition:
- 0
- 0
properties:
host: '${resource.Cloud_vSphere_Machine_1.*}'
account: NL-UTC-P-ANS-01
computerOU: "{{ 'OU=Linux,OU=Servers,OU=Computers,OU=Managed,DC=nl,DC=mdb-lab,DC=com' if ansible_domain == 'nl.mdb-lab.com' else 'OU=Linux,OU=Servers,OU=Computers,OU=Managed,DC=uk,DC=mdb-lab,DC=com' if ansible_domain == 'uk.mdb-lab.com'}}"
admin_group: "{{ lookup('hashi_vault', 'secret=credentials/groups/admins/linuxadmins:GroupName')}}"
admin_group_cn: "{{ lookup('hashi_vault', 'secret=credentials/groups/admins/linuxadmins:cn')}}"
// Extract the serverName and standbyRota from the custom properties (payload)
var custProps = inputProperties.get("customProperties");
// Extract computer name
attVm = custProps.get("serverName");
// Extract domain name and calculate OU
var adDomain = custProps.get("domain");
if (adDomain != '' && != null){
switch(adDomain){
vault write auth/approle/role/sa_ansible \
token_num_uses=0 \
token_ttl=0m \
secret_id_num_uses=0 \
token_no_default_policy=false \
token_policies="acl_sa_ansible"
path "credentials/computers/production/*" {
capabilities = [ "read" ]
}
---
- hosts: Windows
gather_facts: true
tasks:
- name: "What's my name again?"
debug:
msg: '{{ ansible_user }}'
become: yes
---
ansible_shell_type: powershell
ansible_become: yes
ansible_become_method: runas
ansible_become_user: Administrator
ansible_become_password: "{{ lookup('hashi_vault', 'secret=creds/production/{{ inventory_hostname }}:Password')}}"
# Variables
$length = 10 ## characters
$nonAlphaChars = 5
Add-Type -AssemblyName 'System.Web'
# Create the user
$user = "sa_ansible"
$pass = ([System.Web.Security.Membership]::GeneratePassword($length, $nonAlphaChars))
$secureString = ConvertTo-SecureString $pass -AsPlainText -Force
New-LocalUser -Name $user -Password $secureString