Skip to main content

Posts

Showing posts from October, 2023

Basic Ansible understanding when statement

Ansible playbook to illustrate how "when" conditional statement works in Ansible. Ansible playbook below will run a command: "file -s /dev/sdb"  The output of the command will be saved to the variable: save_the_command_output  Yes, the name of the variable can be anything. Just changed it to something that is sensible. save_the_command_output is just a string to illustrate its functionality or usage. After registering or saving the output to a variable, another command will be executed provided the conditional statement "when" is True or the condition is meet or satified. If the conditional statement is not meet then the command will be bypass or will not be executed. On this illustration below, if the conditional statement has been meet. Then a file with a filename "condition_ok" will be written on /tmp directory. Otherwise, if the condition is not meet then no file will be created. Sample playbook below: #=================== --- -  hosts: local

Python Basics - creating virtual environment and activating

 Creating virtual environment in Python is quite important thing to know if you are venturing to the world of Python Programming. Virtual Environment in Python may sound complicated at first if you haven't played around it. Let's delve into it. Why do we need a virtual environment? When we can just installed Python directly to the system. One good thing for creating Python virtual environment, is you can have multiple environments on Python on your system and also different versions. If 2 or 3 people are using the same server or computer, it won't be ideal that each person will use same environment and mess up the work of the other person. And also if your coding is good for a specific version of Python, the syntax may not work on new versions of Python and this is where virtual environment comes into the scenario. How do we create a virtual environment in Python? It's quite straight forward, here's the command. Of course this assumes that Python has been installed