KVM/Qemu Running playbook from host

47 views
Skip to first unread message

Amit Kumar

unread,
Aug 28, 2023, 2:37:35 PM8/28/23
to Ansible Project
Task: checking if pip is installed or not, if not then installing pip.

playbook.yml
---
- name: Install pip on remote linux servers - Only Debian/ubuntu based will work
hosts: ubuntu-servers
gather_facts: false
become: true
vars:
ansible_user: demouser
tasks:
- name: check if pip is installed or not
stat:
path: /usr/bin/pip
register: pip_check
- name: Install pip, if not installed
apt:
name: python3-pip
state: present
when: not pip_check.stat.exists
- name: Print Message
debug:
msg: "pip is installed"
handlers:
- name: Reload bashrc
command: "source ~/.bashrc"
listen: "pip is installed"


inventory.ini file
[ubuntu-servers]
192.168.122.140


Getting the following error:
(venv) user@IdeaPad:~/Documents/MyFiles/dev/other_projects/learning_ansible/playbooks/install-kvm-qemu$ ansible-playbook -i inventory.ini install-pip.yml
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [Install pip on remote linux servers - Only Debian/ubuntu based will work] ****************************************************************************************************

TASK [check if pip is installed or not] ********************************************************************************************************************************************
fatal: [192.168.122.140]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.122.140 port 22: Connection refused", "unreachable": true}

PLAY RECAP *************************************************************************************************************************************************************************
192.168.122.140            : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0  


192.168.122.140: is the IP of the guest, and the guest is running
Any help will be welcomed!

Amit Kumar

unread,
Aug 28, 2023, 2:39:47 PM8/28/23
to Ansible Project
Simple playbook with only debug works but this does not work

Evan Hisey

unread,
Aug 28, 2023, 3:07:40 PM8/28/23
to ansible...@googlegroups.com
What is the simple playbook? The issue is definitely in the ssh connection. Does demouser actually exist on the target host and is the target host the same?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/cb04510f-10d8-4c2e-90b4-4f26c841c767n%40googlegroups.com.

Amit Kumar

unread,
Aug 28, 2023, 3:28:45 PM8/28/23
to Ansible Project
Hi

demouser does exist on the system. The simple playbook is printing debug message. 

---
- name: Testing if everything works on the remote
hosts: ubuntu-servers
gather_facts: false
tasks:
- name: Hello Server
debug:
msg: "Hello Ubuntu Server"

Dick Visser

unread,
Aug 29, 2023, 9:35:00 AM8/29/23
to ansible...@googlegroups.com
Hii

You are overcomplicating things by first doing a stat on /usr/bin/pip.
Besides that, the existence of that path is a very fragile way of detecting if the python3-package is installed.
If you only want to install something if it is not installed already, then that is just what the apt module will do.
That is called idempotence, and IMHO is one of the key features of ansible.
Just have one apt task and be done with it.

The output also notifies you that the group name you use is illegal. It also tells you how to get more information (using -vvvv).
In general, before posting questions, make sure that you don't unnecessarily complicate things by adding obvious errors.
It will give a somewhat careless impression, and it will distract the audience, neither of which will help you get answers to your question.



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

Dick Visser

unread,
Aug 29, 2023, 9:35:03 AM8/29/23
to ansible...@googlegroups.com
On Mon, 28 Aug 2023 at 21:28, Amit Kumar <amit2...@gmail.com> wrote:
Hi

demouser does exist on the system. The simple playbook is printing debug message. 

---
- name: Testing if everything works on the remote
hosts: ubuntu-servers
gather_facts: false
tasks:
- name: Hello Server
debug:
msg: "Hello Ubuntu Server"



Just telling that it is "printing the debug message" is very little information.
Using one or more verbose levels would help.

Also, your debug playbook is not using become, and it not having the "ansible_user: demouser" statement.
Both play an important role in the connection setup.
Make sure you are comparing apples to apples.



Reply all
Reply to author
Forward
0 new messages