pre-tasks doesn't execute before roles...

904 views
Skip to first unread message

Johanna Galarza

unread,
Mar 20, 2020, 11:17:40 AM3/20/20
to Ansible Project
This is my current setup
---
- hosts: all
  pre-tasks:
    - local_action:
        command ansible-galaxy install -r requirements.yml -p . (this install roles roleA, roleB, roleC)
roles:
- role1
- role2

I have always an error message that it says that role1 doesn't exist... and I cannot see the first command being executed even with a debug message - so I have the feeling it is always executing roles first and then pre-tasks, however, I read that pre-task will be run first.... why does this doesn't apply here?

Any idea?

Matt Martz

unread,
Mar 20, 2020, 11:20:33 AM3/20/20
to ansible...@googlegroups.com
Playbooks are parsed all at once, and roles which are "static", are merged into the play at parsing time.  They are required to exist before the playbook runs.  You could however switch to `include_role`, which loads the role when that "task" is encountered.

--
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/884e2977-1bdc-480b-a434-cf820b456815%40googlegroups.com.


--
Matt Martz
@sivel
sivel.net

Stefan Hornburg (Racke)

unread,
Mar 20, 2020, 11:25:13 AM3/20/20
to ansible...@googlegroups.com
No, I think it checks whether the roles are available before running the playbook. So if they are not accessible,
it terminates before performing any tasks.

I would use separate playbooks for the module installation and the execution of the roles.

Regards
Racke

>
> --
> 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 <mailto:ansible-proje...@googlegroups.com>.
> <https://groups.google.com/d/msgid/ansible-project/884e2977-1bdc-480b-a434-cf820b456815%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Johanna Galarza

unread,
Mar 20, 2020, 11:50:08 AM3/20/20
to Ansible Project
so did that I had this error: 
ERROR! 'include_role' is not a valid attribute for a Play


On Friday, March 20, 2020 at 4:20:33 PM UTC+1, Matt Martz wrote:
Playbooks are parsed all at once, and roles which are "static", are merged into the play at parsing time.  They are required to exist before the playbook runs.  You could however switch to `include_role`, which loads the role when that "task" is encountered.

On Fri, Mar 20, 2020 at 10:17 AM Johanna Galarza <johanna...@relayr.io> wrote:
This is my current setup
---
- hosts: all
  pre-tasks:
    - local_action:
        command ansible-galaxy install -r requirements.yml -p . (this install roles roleA, roleB, roleC)
roles:
- role1
- role2

I have always an error message that it says that role1 doesn't exist... and I cannot see the first command being executed even with a debug message - so I have the feeling it is always executing roles first and then pre-tasks, however, I read that pre-task will be run first.... why does this doesn't apply here?

Any idea?

--
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...@googlegroups.com.

Dick Visser

unread,
Mar 20, 2020, 11:52:29 AM3/20/20
to ansible...@googlegroups.com
We use a shell wrapper around two playbooks: one that keeps a directory of roles updated, followed by a playbook that then uses those roles.

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/85481ebf-13a5-c35d-16b6-b869a1268176%40linuxia.de.


--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Johanna Galarza

unread,
Mar 20, 2020, 11:53:13 AM3/20/20
to Ansible Project
I did also that one for role installation and another play for the roles and then run them like there 

- include_playbook: requirements.yml
- include_playbook: project.yml



but same error.. roles are not founded ( which of course are not because the requirements.yaml hasn't done the installation) 
I tried requirement.yamls installing from GitHub but the playbook error was src is cannot be in a play and  then with a task same as above but that didn't install the roles first neither.

On Friday, March 20, 2020 at 4:25:13 PM UTC+1, Stefan Hornburg (Racke) wrote:
On 3/20/20 4:17 PM, Johanna Galarza wrote:
> This is my current setup
> ---
> - hosts: all
>   pre-tasks:
>     - local_action:
>         command ansible-galaxy install -r requirements.yml -p . (this install roles roleA, roleB, roleC)
> roles:
> - role1
> - role2
>
> I have always an error message that it says that role1 doesn't exist... and I cannot see the first command being
> executed even with a debug message - so I have the feeling it is always executing roles first and then pre-tasks,
> however, I read that pre-task will be run first.... why does this doesn't apply here?
>
> Any idea?

No, I think it checks whether the roles are available before running the playbook. So if they are not accessible,
it terminates before performing any tasks.

I would use separate playbooks for the module installation and the execution of the roles.

Regards
          Racke

>
> --
> 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

Matt Martz

unread,
Mar 20, 2020, 11:54:54 AM3/20/20
to ansible...@googlegroups.com
`include_role` is a task, as such it must go under `tasks:`

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/217bb7e0-8269-4c03-a6ae-a073db79b367%40googlegroups.com.

Johanna Galarza

unread,
Mar 20, 2020, 12:58:00 PM3/20/20
to Ansible Project
a shell wrapper? 

> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/884e2977-1bdc-480b-a434-cf820b456815%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/884e2977-1bdc-480b-a434-cf820b456815%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

--
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...@googlegroups.com.

Johanna Galarza

unread,
Mar 20, 2020, 1:00:11 PM3/20/20
to Ansible Project
Got this and it seems that at least the syntax is not complaining anymore but got the following errors.. I feel like I am close

fatal: [192.168.1.161]: FAILED! => {"msg": "privilege output closed while waiting for password prompt:\nsu: Sorry\n"}

This is the current setup

---
- name: Install test 1
  hosts: all
  become: true
  become_method: su
  pre_tasks:
    - debug: msg=' pre roles'
    - local_action:
        command ansible-galaxy install -r requirements.yml -p .

  vars:

  tasks:
    - name: Including roles
      include_role:
name: role1

Matt Martz

unread,
Mar 20, 2020, 1:05:39 PM3/20/20
to ansible...@googlegroups.com
I'm guessing you want `become: false` on the `local_action`, or some variant on that.

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/a78308c7-628f-45b8-81a7-f246b5d17c35%40googlegroups.com.

Johanna Galarza

unread,
Mar 20, 2020, 1:59:10 PM3/20/20
to Ansible Project
apparently     
- local_action:
     become: false
     command ansible-galaxy install -r requirements2.yml -p .

ERROR! unexpected parameter type in action: <class 'NoneType'>

vinoth kumar

unread,
Mar 22, 2020, 12:47:01 PM3/22/20
to ansible...@googlegroups.com
What is your ansible.cfg looks . Actually it’s stores on your home directory/.ansible. Do a change on cfg that points to roles_path to this directory as well. This wil help you if you get roles doesn’t exist. Are you running in ansible engine or from ansible tower ?

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/af25d1fe-c566-476c-a031-e49f9a99f500%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages