5

I have an Ansible-Playbook file that is supposed to create an apache2 server on localhost, create/copy some documents, install Git, and clone a repo. However, everytime I try to execute the file I keep getting this error:

fatal: [myserver]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"failed": true, "module_stderr": "/usr/bin/env: ‘python’: No such file or directory\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 127}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}

And this is my ansible-playbook file:

---
- hosts: myserver
  become: true
  remote_user: admin
  vars_files:
    - default.yml

  tasks:
    - name: Install Apache
      apt: name=apache2 update_cache=yes state=latest

- name: Create document root for domain
  file:
    path: "/var/www/{{ http_host }}"
    state: directory
    owner: "user"
    mode: '0755'

- name: Copy index page
  template:
    src: "index.html"
    dest: "/var/www/html/index.html"
    mode: '0755'

- name: Set up VirtualHost
  template:
    src: "apache2.conf"
    dest: "/etc/apache2/sites-available/{{ http_conf }}"
    mode: '0755'
  notify: restart-apache

- name: "HTTP on port {{ http_port }}"
  ufw:
    rule: allow
    port: "{{ http_port }}"
    proto: tcp

- name: Install Git
  apt:
    name: git
    state: present
    update_cache: yes

- name: Clone the repo
  ansible.builtin.git:
    repo: https://github.com/User/Repo
    dest: /home/user
    accept_hostkey: yes
    clone: yes
    update: yes
  become: no

  handlers:
    - name: restart-apache
      service:
        name: apache2
        state: restarted

I was originally testing this file on an Ubuntu VM, and it did work up until the task for cloning the repo. However, the VM I originally built this on got corrupted, so I had to create another Ubuntu VM and that's what I'm currently working on and where I am experiencing this issue.

I have ansible and python installed, so I don't think it's that.

What could the issue be?

Limbo
  • 139
  • 1
  • 2
  • 8
  • 5
    Python is not installed on your target vm. It is required for all ansible modules (except for `raw` and `script`) including for the `setup` module which is played automatically by default during facts gathering on your target before all other tasks. – Zeitounator Apr 27 '22 at 11:38
  • 3
    Since I were stumbling about the same problem in the past, I've posted an answer for [How to initialize the system correctly](https://stackoverflow.com/a/64817243/6771046). In short you could try `ln -s /usr/bin/python3 /usr/bin/python`. – U880D Apr 27 '22 at 19:36
  • That seems to have solved it, then. Thanks! – Limbo Apr 27 '22 at 23:54
  • 1
    Or change the `ansible_python_interpreter` variable to the appropriate value. – β.εηοιτ.βε Apr 29 '22 at 07:45

0 Answers0