0

My needs: Write a playbook which can install apache if the user wants to, while the playbook is running by typing yes or no.

apache_prompt.yml

  hosts: slaves  
  vars_prompt:
    - name: install_apache
      prompt: "Do yo want to install apache? (yes/no)?"

  tasks:
    - name: if 'yes'
      include_tasks: apache.yml
      when: install_apache == 'yes'

apache.yml

---
 - name: apache install
   apt:
     name: apache2
     state: present

These playbooks are integrated in a role folder "apache"

My /tasks/main.yml

---
- import_tasks: apache_prompt.yml

My main playbook, which I use for installing some stuffs thanks to roles:


 - hosts: slaves
   roles:
      - ntp
      - nmap
      - tcpdump
      - unattended-upgrades
      - apache

I only have trouble with the apache role.

------------------EDIT-------------------

I've got syntax error since I wrote my question. I tried to modify the

apache_prompt.yml

until now and i got this error: ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

---
- hosts: slaves
  vars_prompt:
    - name: "install_apache"
      prompt: "Do yo want to install apache? (yes/no)?"

  tasks:
    - include_tasks: apache.yml
      when: install_apache == 'yes'
  • 1
    Welcome to U&L. You haven't specified what your question exactly is. You seem to have already set the prompts using the 'apache_prompt.yml' file. Is there a problem with this configuration? – Haxiel Mar 1 at 11:14
  • I assume your problem lies within the check when: install_apache == 'yes', is that correct? – Panki Mar 1 at 12:06
  • I edited my question. My playbook contains syntax errors – Ludo Sachot Mar 1 at 14:02
  • @Ludo. Check syntax with "ansible-lint <playbook>". – Vladimir Botka Mar 1 at 14:22
  • @VladimirBotka Finally i wrote an another playbook. He runs like a charm when lauched with ansible-playbook /path_to_playbook/playbook.yml but i get a error when i run my main playbook which contains the roles. i tried "ansible-lint my_main_playbook" and it say "(no action detected in task. This often indicates a misspelled module name, or incorrect module path.)" – Ludo Sachot Mar 1 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.