cancel
Showing results for 
Search instead for 
Did you mean: 
jadolyo
Flight Engineer
Flight Engineer
  • 4,568 Views

Error in Guided Exercise: Creating Roles - Chapter 7 section 4

Hello,

I was doing the guided exercise on my local machine and I am having an error I didn't figure out why it's showing, Can anyone help?

 

ERROR! the role 'myvhost' was not found in /home/jadolyo/roles/myvhost/roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/jadolyo/roles/myvhost

The error appears to be in '/home/jadolyo/roles/myvhost/use-vhost-role.yml': line 10, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

roles:
- myvhost
^ here

 

my use-vhost-role.yml

 

  1 ---
  2 - name: Use myvhost role playbook
  3   hosts: webservers
  4   pre_tasks:
  5   ¦ - name: pres_tasks message
  6   ¦ ¦ ansible.builtin.debug:
  7   ¦ ¦ ¦ msg: 'Ensure web server configuration.'
  8
  9   roles:
 10   ¦ - myvhost
 11
 12   post_tasks:
 13   ¦ - name: HTML content is installed
 14   ¦ ¦ ansible.builtin.copy:
 15   ¦ ¦ ¦ src: files/html/
 16   ¦ ¦ ¦ dest: "var/www/vhost/{{ ansible_hostname }}"
 17
 18   ¦ - name: post_tasks message
 19   ¦ ¦ ansible.builtin.debug:
 20   ¦ ¦ ¦ msg: 'Web server is configured.'

 

 

roles_error.png

16 Replies
khokha
Flight Engineer
Flight Engineer
  • 1,875 Views

@jadolyo 

Thanks alooooooooooooooooooooooooooooot.

Rabna ykrmk w ys3dk w ywaf2k.

جزاك الله خيرا كثيرا

May i ask you again if i had trouble in completing the entire environment setup, please?

jadolyo
Flight Engineer
Flight Engineer
  • 1,874 Views

@khokha 

Oh, You are Arab, You are most welcome.

 

جزانا وإياكم الجنة في الفردوس الأعلى، اللهم آمين

دعوة صادقة في ظهر الغيب بصلاح الحال، وهكون سعيد جدا.


Yes for sure, If you need help anytime, I will be happy to give a hand.

khokha
Flight Engineer
Flight Engineer
  • 1,868 Views

اميين يا رب نحن و اياكم

هدعيلك كتيييير ان شاء الله

شكراااااا

jadolyo
Flight Engineer
Flight Engineer
  • 1,821 Views

Hi @khokha 

I saw an email notification you are asking about something but I see you deleted your message, Anyway, I would like to share some tips on my configuration.

1- /etc/hosts file I did some configuration to each VM and to my main controller as below.

192.168.1.50 controller controller.lab.example.com
192.168.1.51 node1 node1.lab.example.com
192.168.1.52 node2 node2.lab.example.com
192.168.1.53 node3 node3.lab.example.com

 

So every time I SSH I just write ssh controller or ssh node1 you can modify MobaXterm hosts file as well so you can easily ssh without writing the IP address.

 

2- Created a user let's say "Ansible" on my controller and each VM too and for sure copied the public key from the controller to each VM, You should know this from RHCSA, Right!

 

3- the ansible.cfg and inventory you can create your own it depends on your naming I am using nodeX you might use serverX my inventory as an example looks like as below

ansible.cfg

inventory = inventory

* Note: I created a directory and inside that directory other directories have it's on playbooks and configurations sometimes I use [privilege_escalation] as below

[privilege_escalation]
become=true
become_method=sudo
become_user=root
become_ask_pass=false

My static inventory looks like as below, you might change the names it doesn't matter it's your choice.

[webservers]

node1.lab.example.com

node2.lab.example.com

[dbservers]

node3.lab.example.com

node4.lab.example.com

 

As you know from RHCSA you need to modify your hostname file on each VM to meet the requirements, and as you know too you might need to create a file inside /etc/sudoers.d/ directory as your user's name and add a line as below, as you know you need the root to create that file if I am not wrong.

 

ansible ALL=(ALL) NOPASSWD: ALL

 

I hope this can help you to make things easier, Have a nice day.

khokha
Flight Engineer
Flight Engineer
  • 1,804 Views

Hi @jadolyo ,

Thanks for your reply i was having some issues with setting up the environment correctly, but fortunatelly i figures it out and it now works fine.

Again thanks for your reply and your help.

Have a great day

 

ric
Flight Engineer Flight Engineer
Flight Engineer
  • 1,162 Views

Hi everyone!

I'm doing a bit of a topic / thread hijack here, because I'm also having an error in the "Guided Exercise: Creating Roles - Chapter 7 section 4". In my case, the syntax check for the "use-vhost-role.yml" playbook runs correctly:

 

[student@workstation role-create]$ ansible-navigator run use-vhost-role.yml --syntax-check -m stdout
playbook: /home/student/role-create/use-vhost-role.yml

 

... but running the playbook returns an error for "servera.lab.example.com", for the task "Ensure vhost file is installed" :

 

[student@workstation role-create]$ ansible-navigator run use-vhost-role.yml -m stdout

PLAY [Use myvhost role playbook] ***********************************************

TASK [Gathering Facts] *********************************************************
ok: [servera.lab.example.com]

TASK [pre_tasks message] *******************************************************
ok: [servera.lab.example.com] => {
"msg": "Ensure web server configuration."
}

TASK [myvhost : Ensure httpd is installed] *************************************
changed: [servera.lab.example.com]

TASK [myvhost : Ensure httpd service is started] *******************************
changed: [servera.lab.example.com]

TASK [myvhost : Ensure vhost file is installed] ********************************
fatal: [servera.lab.example.com]: FAILED! => {"changed": false, "checksum": "f71b650f8607db136b9c9325ce70b0b38271e6a5", "msg": "Unsupported parameters for (ansible.legacy.copy) module: notify. Supported parameters include: mode, checksum, owner, validate, serole, content, _original_basename, setype, directory_mode, remote_src, seuser, src, backup, follow, dest, attributes (attr), unsafe_writes, force, local_follow, selevel, group."}

PLAY RECAP *********************************************************************
servera.lab.example.com : ok=4 changed=2 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Please review the log for errors.

 

For reference, here's the content of that playbook:

 

[student@workstation role-create]$ cat use-vhost-role.yml
---
- name: Use myvhost role playbook
hosts: webservers
pre_tasks:
- name: pre_tasks message
ansible.builtin.debug:
msg: 'Ensure web server configuration.'


roles:
- myvhost

post_tasks:
- name: HTML content is installed
ansible.builtin.copy:
src: files/html/
dest: "/var/www/vhost/{{ansible_hostname}}"

- name: post_tasks message
ansible.builtin.debug:
msg: 'Web server is configured.'

 

Am I doing something wrong?

Thanks in advance

EDIT: Got it! Solved! The problem was an indentation problem inside the file "tasks/main.yml". I had wrongly put the following lines with the same indentation level of the lines inside the "ansible.builtin.template:" block instead of having the same indentation level of the "ansible.builtin.template:" line:

notify:
- restart httpd

Chetan_Tiwary_
Community Manager
Community Manager
  • 1,136 Views

@ric Glad that you were able to indentify the indentation error in your yml !

Join the discussion
You must log in to join this conversation.