Installing ansible with pip

First, we need to ensure that python3.9 and pip are available.

 

if not available, please read my install pyhon3.9 post below.

https://blog.innobyte.com.tr/?p=129

if so, pip is available proceed installation step but please note that do not install ansible on root user.

pip3.9 install ansible

Verifying ansible installation.

ansible --version

 

As you can see, the executable location is under the $HOME/.local/bin directory. You can add it to the PATH environment variable in the bash_profile.

Now, we can create configuration file.

sudo mkdir /etc/ansible
sudo chown ansible:ansible /etc/ansible
ansible-config init --disabled -t all > /etc/ansible/ansible.cfg

 

Let’s try a simple ansible playbook to test without creating inventory file. We will be using localhost.

create a test.yml file with below lines and save it.

- hosts: localhost
  tasks:
    - name: Get user name
      shell: whoami
      register: theuser

    - name: Get host name
      shell: hostname
      register: thehost

    - debug: msg="I am {{ theuser.stdout }} at {{ thehost.stdout }}"

 Execute with following command.

ansible-playbook test.yml

 

Ok, that’s it!

This entry was posted in Ansible, Linux and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *