Pages

Wednesday, January 19, 2022

Manage Vmware Machines With Ansible

Here we are looking on how to use Ansible to connect to vCenters and manage VMs. The focus will be on using quick playbooks for cloning and deleting a current template VM.

We can see the playbook for the creation process for cloning and deleting VMs. The playbook creation process will involve setting up variables, tasks, and handlers, and will be broken down into simple, easy-to-follow steps. Sample playbooks will be provided as a starting point for managing VMs in vCenter using Ansible.

Clone a VM in Vcenter with Ansible Playbook

- hosts: localhost
gather_facts: no
vars:
vcenter_server: "xxx.xxx.xxx.xxx"
vcenter_user: "User-Name"
vcenter_pass: "Password"
datacenter_name: "DC-Name"
cluster_name: "xxx.xxx.xxx.xxx"
resources_pool: "RG-Name"
template_vm: "Template-Name"
serv:
- vm1
- vm2

tasks:
- name: Clone the template
vmware_guest:
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
resource_pool: "rahul-test"
validate_certs: False
name: "{{ item }}"
template: "{{ template_vm }}"
datacenter: "{{ datacenter_name }}"
folder: /{{ datacenter_name }}/vm
state: poweredon
wait_for_ip_address: yes
register: "r"
with_items: "{{ serv }}"
- debug :
msg: "This is the Host-IPs: {{ item.instance.ipv4 }} {{ item.instance.hw_name }}"
with_items: "{{ r.results}}"
loop_control:
label: "{{ item.instance.hw_name }}"




Shutdown a VM in Vcenter with Ansible Playbook

- hosts: localhost
gather_facts: no
vars:
vcenter_server: "xxx.xxx.xxx.xxx"
vcenter_user: "User-Name"
vcenter_pass: "Password"
datacenter_name: "DC-Name"
cluster_name: "xxx.xxx.xxx.xxx"
tasks:
- name: Shutdown the template
vmware_guest:
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
validate_certs: False
name: "{{ item}}"
datacenter: "{{ datacenter_name }}"
folder: /{{ datacenter_name }}/vm
state: poweredoff
wait_for_ip_address: yes
loop:
- vm1
- vm2


Delete a VM in Vcenter with Ansible Playbook

- hosts: localhost
gather_facts: no
vars:
vcenter_server: "xxx.xxx.xxx.xxx"
vcenter_user: "User-Name"
vcenter_pass: "Password"
datacenter_name: "DC-Name"
cluster_name: "xxx.xxx.xxx.xxx"
tasks:
- name: Delete the template
vmware_guest:
hostname: "{{ vcenter_server }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
validate_certs: False
name: "{{ item}}"
datacenter: "{{ datacenter_name }}"
folder: /{{ datacenter_name }}/vm
state: absent
wait_for_ip_address: yes
loop:
- vm1
- vm2



Friday, March 12, 2021

Ansible for Vcenter Module not found error

When working with vCenter and Ansible, you may encounter an error that says "vmware_guest Module not found." This error occurs when the vmware_guest module is not installed on your system.

To resolve this error, you need to install the community.vmware collection, which contains the vmware_guest module. You can do this by running the following command:

To install it use: ansible-galaxy collection install community.vmware.

This command will download and install the community.vmware collection, which contains the vmware_guest module. Once installed, you should be able to use the module in your Ansible playbooks without encountering any errors.




Tuesday, March 9, 2021

Test WinRm connection to Windows Env

To check if WinRM (Windows Remote Management) is enabled in a Windows Server, you can use the following commands:

Test-NetConnection -ComputerName XX -Port 5986

This command tests the connection to port 5986, which is the default port used by WinRM over HTTPS.

Test-NetConnection -ComputerName XX -Port 5985

This command tests the connection to port 5985, which is the default port used by WinRM over HTTP.

If the above commands return successful results, it means that WinRM is enabled and running on the specified server.

Additionally, you can also use the following command to check if WinRM is configured properly on a remote server:

Test-WSMan -ComputerName XX

This command tests the Windows Remote Management (WinRM) service on a remote server and returns the current configuration status of WinRM.

Sed Command in MAC

The sed command is used to manipulate and edit text in Unix-based operating systems like macOS.

Method to use Sed in Mac

sudo sed -i "/kube/d" /etc/hosts

give error sed: 1: "/etc/hosts": extra characters at the end of h command


In the first command you provided, sudo sed -i "/kube/d" /etc/hosts, the -i option tells sed to edit the file in place, and /kube/d is the command that tells sed to delete any lines containing the string "kube" in the /etc/hosts file. However, this command does not work on macOS as it requires the -i option to have a backup file extension specified. The error message "sed: 1: "/etc/hosts": extra characters at the end of h command" is indicating that the command is not properly formatted for macOS.

To fix this, you can use the following command: sudo sed -i '' '/kube/d' /etc/hosts. The empty quotes after -i specify that no backup file should be created, and the '' is necessary for macOS to recognize the command properly. The /kube/d command remains the same and tells sed to delete any lines containing the string "kube" in the /etc/hosts file.

Following Syntax Worked. 
sudo sed -i '' '/kube/d' /etc/hosts


Sunday, August 16, 2020

Converting Text Case in Linux: Exploring Powerful Command-Line Tools

In the realm of command-line utilities, Linux offers a plethora of versatile tools that empower users to perform a wide range of tasks efficiently. One such task involves converting the case of text within a file. Whether you're looking to transform text to lowercase or uppercase, Linux provides multiple command-line options to achieve this. In this article, we'll delve into the process of converting text case using four prominent tools: dd, awk, perl, and sed.


Converting Text to Lowercase

Using dd

The dd command, renowned for its data manipulation capabilities, can also be employed to convert text to lowercase.

$ dd if=input.txt of=output.txt conv=lcase

Leveraging awk

awk, a versatile text processing tool, offers a succinct way to convert text to lowercase.

$ awk '{ print tolower($0) }' input.txt > output.txt

The Magic of perl

Perl enthusiasts can harness the power of this scripting language to achieve case conversion.
$ perl -pe '$_= lc($_)' input.txt > output.txt

Transforming with sed

For those who appreciate the elegance of sed, this command can seamlessly convert text to lowercase.

$ sed -e 's/\(.*\)/\L\1/' input.txt > output.txt

Converting Text to Uppercase

dd for Uppercase Conversion

Using dd to convert text to uppercase is equally achievable.

$ dd if=input.txt of=output.txt conv=ucase

awk for Uppercase Transformation

awk enthusiasts can employ its capabilities for converting text to uppercase.

$ awk '{ print toupper($0) }' input.txt > output.txt

Uppercase Conversion with perl

Perl's power shines again in transforming text to uppercase.

$ perl -pe '$_= uc($_)' input.txt > output.txt

sed for Uppercase Conversion

Converting text to uppercase using sed is both efficient and effective.

$ sed -e 's/\(.*\)/\U\1/' input.txt > output.txt


Tuesday, April 14, 2020

Configure AWS Login With Azure AD Enterprise App

The idea is to enable users to sign in to AWS using their Azure AD credentials. This can be achieved by configuring single sign-on (SSO) between Azure AD and AWS. The process involves creating an enterprise application in Azure AD and configuring the AWS application to use Azure AD as the identity provider. Once this is set up, users can log in to AWS using their Azure AD credentials and access the AWS resources that they have been authorized to use. The tutorial provided by Microsoft explains the steps involved in setting up this SSO configuration between Azure AD and AWS.



  1. Azure >> Enterprise APP >> <<Configure Azure AD SSO
    1. Deploy Amazon Web Services Developer App
    2. Single Sign On >>.SAML
      1. Popup to save
        1. Identifier: https://signin.aws.amazon.com/saml
        2. Reply URL: https://signin.aws.amazon.com/saml
      2. Save
    3. SAML Signing Certificate
      1. Download "Federation Metadata XML"
    4. Add the AD user's to Application's User' and Group
  2. AWS >> IAM >> Identity provider
    1. Create
      1. SAML
      2. AZADAWS
      3. Upload the Metadata XML
    2. Verify Create
  3. AWS>> IAM >> ROLE << This Role will Come in Azure Application
    1. SAML 2.0 Federations
      1. Choose :  Earlier Created Identity provider
      2. Allow programmatic and AWS Management Console access
      3. Choose required permissions
      4. Create the role with Appropriate name
  4. AWS >> IAM >> POLICIES <<  This policy will allow to fetch the roles from AWS accounts.
    1. Choose JSON
      1. { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "iam:ListRoles" ], "Resource": "*" } ] }
    2. Name : AzureAD_SSOUserRole_Policy.
    3. Create the Policy
  5. AWS >> IAM >> USER
    1. Name : AzureADRoleManager
    2. Choose Programmatic access
    3. Permission : Attach existing polices
      1. Choose : AzureAD_SSOUserRole_Policy
    4. Create User
    5. Copy Access and Secret key
  6. Azure Enterprise App >> Choose Amazon Web Services App which was deployed
    1. Provisoing
      1. Make it automatic
      2. Give Aws Access and Secret key
      3. Test and Save
      4. Make the "Provisioning Status" to ON
      5. Wait for a sync to complete
      6. Once Sync is Completed got the user's and Groups
        1. Choose the user, select Click EDIT
        2. Choose the AWS Role






Saturday, February 8, 2020

Issue with Mission Control in Mac 10.15.13

If you are experiencing issues with Mission Control on Mac version 10.15.13 after an update, there is a fix that involves using the Terminal app. Simply type or copy the following command: "defaults write com.apple.dock mcx-expose-disabled -bool FALSE", then type "killall Dock" to stop the Dock, which will automatically restart. After this, the Exposé activation should take effect.
Fix
  • Go to the Terminal app
  • Type or copy: defaults write com.apple.dock mcx-expose-disabled -bool FALSE 
  • Then type: killall Dock to stop the Dock that will then automatically be restarted. Only then the Exposé activation will take effect.