Saturday, June 5, 2021

use windows facts in ansible

check available facts for that host 

ansible -m setup hostname

---
- hosts: win
  tasks:
    - name: Get custom facts
      debug:
      msg: The custom fact is {{ansible_local.date_time}}

Friday, June 4, 2021

To enable kerberos authentication for ansible.

for kerberos
yum install python3-devel
yum install krb5-workstation
yum install krb5-devel
yum install krb5-libs
pip install kerberos
pip3 install pywinrm[kerberos]


edit below info in /etc/krb5.conf file then run kinit Administrator@AREA51.COM and kinit -S HOST/WIN-DQTK4K8NQ55.AREA51.COM

# To opt out of the system crypto-policies configuration of krb5, remove the
# symlink at /etc/krb5.conf.d/crypto-policies which will not be recreated.
includedir /etc/krb5.conf.d/

[logging]
    default = FILE:/var/log/krb5libs.log
    kdc = FILE:/var/log/krb5kdc.log
    admin_server = FILE:/var/log/kadmind.log

[libdefaults]
    dns_lookup_realm = false
    ticket_lifetime = 24h
    renew_lifetime = 7d
    forwardable = true
    rdns = false
    pkinit_anchors = FILE:/etc/pki/tls/certs/ca-bundle.crt
    spake_preauth_groups = edwards25519
    default_realm = AREA51.COM
    default_ccache_name = KEYRING:persistent:%{uid}
    default_tgs_enctypes = aes256-cts-hmac-sha1-96 rc4-hmac des-cbc-crc des-cbc-md5
    default_tkt_enctypes = aes256-cts-hmac-sha1-96 rc4-hmac des-cbc-crc des-cbc-md5
    permitted_enctypes = aes256-cts-hmac-sha1-96 rc4-hmac des-cbc-crc des-cbc-md5
[realms]
#kdc = AREA51.COM
 AREA51.COM = {
     kdc = area51.com:88
     admin_server = area51.com:749
 }

[domain_realm]
 .area51.com = AREA51.COM
 area51.com = AREA51.COM

https://docs.ansible.com/ansible-tower/3.1.3/html/administration/kerberos_auth.html
https://access.redhat.com/solutions/4911041
for domain controller relation issue
https://docs.microsoft.com/en-us/troubleshoot/windows-server/networking/verify-srv-dns-records-have-been-created

Configure VMware.PowerCLI on powershell

 


Install-Module -Name VMware.PowerCLI

Set-PowerCLIConfiguration -Scope User -InvalidCertificateAction warn

To enable virtualization support on VM

 

To enable virtualization support on VM

add below mentioned line in vm vmx file 


vhv.enable = "TRUE"

####################################

evcCompatibilityMode = "FALSE"

monitor.phys_bits_used = "40"

vmotion.checkpointFBSize = "4194304"

cleanShutdown = "TRUE"

softPowerOff = "FALSE"

tools.syncTime = "FALSE"

vhv.enable = "TRUE"

ide1:0.startConnected = "FALSE"

ide1:0.allowGuestConnectionControl = "TRUE"

config.readOnly = "FALSE"

ethernet0.virtualDev = "vmxnet3"

ethernet0.networkName = "VM Network"

ethernet0.addressType = "generated"

ethernet0.uptCompatibility = "TRUE"

ethernet0.present = "TRUE"

ethernet0.pciSlotNumber = "160"

ethernet0.generatedAddress = "00:0c:29:de:59:84"

ethernet0.generatedAddressOffset = "0"

ethernet1.pciSlotNumber = "192"

ethernet1.virtualDev = "vmxnet3"

ethernet1.networkName = "VM Network"

ethernet1.addressType = "generated"

ethernet1.uptCompatibility = "true"

ethernet1.present = "TRUE"

ethernet1.generatedAddress = "00:0c:29:de:59:8e"

ethernet1.generatedAddressOffset = "10"

extendedConfigFile = "ESXi6.7.vmxf"

vhv.enable = "TRUE"

Ansible Playbook to create or remove windows directory

Ansible Playbook to create or remove windows directory

---
- hosts: win
  tasks:
    - name: create directory
      win_file:
        path: 'c:\ry\ansibletest'
        state: directory

---
- hosts: win
  tasks:
    - name: create directory
      win_file:
        path: 'c:\ry\ansibletest'
        state: absent

To enable Sudo access on particular without password.

 edit visudo file on ubuntu and centos

add this line to get sudo access on ansible account without password

## Allow root to run any commands anywhere

root    ALL=(ALL)       ALL

ansible ALL=(ALL)       NOPASSWD: ALL


now for sudo access need to run command with -b 

ansible node -b -a "reboot"


ansible node* -m setup to check node info

To enable key for connect password less node from ansible.

now will generate key for password less authentication from ansible controller to node1
create ansible user on node1 
useradd ansible 

sudo ansible
cd ~
ls -l
ls -la
mkdir .ssh/
vi .ssh/authorized_keys

now goto contoller
ssh-keygen
cat /root/.ssh/id_rsa.pub
copy the code key and go back to node1 
paste there and save file
chmod -R 700 .ssh/ on node1 

not try to connect node1 from controller. it should connect without password.

now edit hosts files under /etc/ansible/hosts on cotroller machine

add the entry of host ip

also edit the /etc/ansible/ansible.cfg file for remote_user= ansible

now try ansible all -m ping 

ansible all -a "uptime"