Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom playbook can't find "task_src" lookup plugin #117

Closed
carlalexander opened this issue May 31, 2015 · 37 comments
Closed

Custom playbook can't find "task_src" lookup plugin #117

carlalexander opened this issue May 31, 2015 · 37 comments

Comments

@carlalexander
Copy link

I'm trying to build a wordpress application role in a separate role/playbook. I'm using the phpmyadmin role as a base. So you get dependencies that look like:

dependencies:

  - role: debops.php5
    php5_packages: [ 'php5-mysqlnd', 'php5-mcrypt', 'php5-gd', 'php5-dev' ]
    php5_pools: [ '{{ wordpress_php5_pool }}' ]
    when: wordpress_dependencies is defined and wordpress_dependencies
    tags: [ 'mysql', 'wordpress' ]

  - role: debops.nginx
    nginx_servers: [ '{{ wordpress_nginx_server }}' ]
    nginx_upstreams: [ '{{ wordpress_nginx_upstream_php5 }}' ]
    when: wordpress_dependencies is defined and wordpress_dependencies
    tags: [ 'mysql', 'wordpress', 'nginx' ]

  - role: debops.secret

The role is in its own playbook called wordpress.yml that follows the application.yml standard.

---

- name: Manage WordPress service
  hosts: 'wordpress'
  sudo: True

  roles:
    - { role: wordpress, tags: wordpress }

I get this error when I run debops wordpress:

ERROR: Failed to template {{ lookup('task_src', 'nginx/pre_main.yml') }}: lookup plugin (task_src) not found

It finds the plugin if I just assign the host to the group debops_nginx and run debops. It only happens if I use a custom role/playbook where I use debops.nginx as a dependency. The playbook runs fine without it.

I tried copying the task_src.py plugin into my debops project, but it's still not picked up. I also tried overwriting the lookup_plugins in .debops.cfg to point to it. That didn't work either. It doesn't seem like lookup_plugins is picked up at all with a custom playbook.

@drybjed
Copy link
Member

drybjed commented May 31, 2015

Hi, sorry for taking so long to respond. My development environment looks like this:

  • DebOps roles and playbooks are installed in ~/.local/share/debops/, just by running debops-update;
  • I keep my project directory in ~/src/projects/devel/, custom playbooks are in ~/src/projects/devel/playbooks/, custom roles are in ~/src/projects/devel/roles/;

I just tried your setup by adding a wordpress playbook as ~/src/projects/devel/playbooks/wordpress.yml the same as yours, and creating a rudimentary role with debops.nginx dependency as ~/src/projects/devel/roles/debops.wordpress/. When I run debops wordpress, I don't see any errors.

So, let's try to recap - what's your Ansible Controller based on, MacOSX, Linux, Windows? Do you have DebOps roles and playbooks installed in ~/.local/share/debops/? I assume that your ran debops script at least once so that it generated ansible.cfg in the project directory, can you show it?

Also, I'm developing all my roles by doing basically what you have done, haven't had any problems like that yet.

@carlalexander
Copy link
Author

I'm on MacOSX. I installed Debops using pip install debops. Everything is up to date. All the Debops playsbooks are in /Users/carlalexander/Library/Application Support/debops which is the same as ~/Library/Application Support/debops in the "Getting started" guide.

Here is the ansible.cfg generated by Debops. You'll see that the correct path is there.

# Ansible configuration file generated by DebOps, all changes will be lost.
# You can manipulate the contents of this file via `.debops.cfg`.

[ssh_connection]

[paramiko]

[defaults]
filter_plugins = "/Users/carlalexander/Projects/carlalexander/debops/ansible/filter_plugins":"/Users/carlalexander/Library/Application Support/debops/debops-playbooks/playbooks/filter_plugins":"/usr/share/ansible/filter_plugins"
hostfile = /Users/carlalexander/Projects/carlalexander/debops/ansible/inventory
roles_path = /Users/carlalexander/Projects/carlalexander/debops/roles:/Users/carlalexander/Projects/carlalexander/debops/ansible/roles:/Users/carlalexander/Library/Application Support/debops/debops-playbooks/playbooks/../roles:/Users/carlalexander/Library/Application Support/debops/debops-playbooks/playbooks/roles:/etc/ansible/roles
connection_plugins = "/Users/carlalexander/Projects/carlalexander/debops/ansible/connection_plugins":"/Users/carlalexander/Library/Application Support/debops/debops-playbooks/playbooks/connection_plugins":"/usr/share/ansible/connection_plugins"
library = /Users/carlalexander/Projects/carlalexander/debops/ansible/library:/Users/carlalexander/Library/Application Support/debops/debops-playbooks/playbooks/library:/usr/share/ansible/library
vars_plugins = "/Users/carlalexander/Projects/carlalexander/debops/ansible/vars_plugins":"/Users/carlalexander/Library/Application Support/debops/debops-playbooks/playbooks/vars_plugins":"/usr/share/ansible/vars_plugins"
ansible_managed = This file is managed remotely, all changes will be lost
action_plugins = "/Users/carlalexander/Projects/carlalexander/debops/ansible/action_plugins":"/Users/carlalexander/Library/Application Support/debops/debops-playbooks/playbooks/action_plugins":"/usr/share/ansible/action_plugins"
callback_plugins = "/Users/carlalexander/Projects/carlalexander/debops/ansible/callback_plugins":"/Users/carlalexander/Library/Application Support/debops/debops-playbooks/playbooks/callback_plugins":"/usr/share/ansible/callback_plugins"
lookup_plugins = "/Users/carlalexander/Projects/carlalexander/debops/ansible/lookup_plugins":"/Users/carlalexander/Library/Application Support/debops/debops-playbooks/playbooks/lookup_plugins":"/usr/share/ansible/lookup_plugins"

When I check the content of /Users/carlalexander/Library/Application Support/debops/debops-playbooks/playbooks/lookup_plugins, all lookup plugins are present. Ansible doesn't pick them up for some reason.

I'd clarify that the full command that I run is debops wordpress -u root. I added some traces in the Debops executable, but it seemed to behave as it should.

The only difference with the setup that you described is that my custom playbook is in the ansible directory created with debops-init.

The whole thing is very odd.

@drybjed
Copy link
Member

drybjed commented May 31, 2015

I remember that there were some problems with space in the path ("Application Support"), could you move the DebOps playbooks to a path without space and try it? Also, what happens when you run:

ansible-playbook playbooks/wordpress.yml -u root

Basically, bypass the debops script and run ansible-playbook directly with file generated by debops, what happens then?

Could you try doing the same in a Linux VM? It looks to me like a MacOSX issue rather than DebOps scripts or Ansible. Ufortunately, I don't use Macs at the moment. :-) You could try coming over to #debops @ FreeNode, some users there use Macs, perhaps they could help with debugging.

@carlalexander
Copy link
Author

Yup, that was the issue! I symlinked the debops install to /usr/local/share/debops. That fixed the issue. I didn't think it was the cause. I saw some code dealing with the issue in the debops binary. I assumed it was working.

Thanks for the help!

@drybjed
Copy link
Member

drybjed commented May 31, 2015

@carlalexander So this is Ansible issue after all? So that means that on MacOSX putting playbooks in current default (Application Support) will cause these sort of errors each time for everyone... I would change the default then, what do you think?

@carlalexander
Copy link
Author

I think you should. I'm no expert, but I think somewhere under /usr/local is better. That's where I see most of the things get installed.

@drybjed
Copy link
Member

drybjed commented May 31, 2015

No, /usr/local/ is wrong in this case, the idea is to have the playbooks and roles per-user account. On Linux it's in ~/.local/share/, but on MacOSX the canonical place apparently is ~/Library/Application Support/. Is there another path without spaces that's in the user home directory and can be used for this purpose?

I guess we could go with ~/.local/share/ as well, but that might be jarring for MacOS X users... Any suggestions, @htgoebel, @rchady, @mboyer?

@htgoebel
Copy link
Contributor

htgoebel commented Jun 1, 2015

This clearly is a bug in Ansible, still present in 1.7.2, see ansible/ansible#8555. I suggest keeping the applications behaviour of debops, which means no change. But if you decide to change, I'm fine with it - it's your project :-)

@drybjed
Copy link
Member

drybjed commented Jun 1, 2015

Then perhaps we should ask @bcoca or @abadger if they are looking into fixing that upstream first...

@rchady
Copy link

rchady commented Jun 1, 2015

Wait, why should the playbooks/roles be per-user account? Custom ones, sure and inventory sure... but the debops stuff should be global in nature, unless I am missing the question here. I personally dislike much of the ~/Library stuff for OSX and instead use the underlying unixy layout.

@drybjed
Copy link
Member

drybjed commented Jun 1, 2015

DebOps scripts sure, they can be in /usr/local/bin/, but I think that playbooks and roles should be user-based, since you don't need root permissions to update them.

@htgoebel
Copy link
Contributor

htgoebel commented Jun 1, 2015

why should the playbooks/roles be per-user account?

This issue is not about this question. This issue is about spaces in paths on OSX. They may happen even in global directories.

@rchady
Copy link

rchady commented Jun 1, 2015

Regarding spaces in paths, yeah that is an ansible issue.

Regarding where the playbooks/roles are at, I believe a far better solution would be to rely on the global /etc/debops.cfg file to indicate where they should be installed. I, for one, do not want per-user roles/playbooks.

@drybjed
Copy link
Member

drybjed commented Jun 1, 2015

I think /etc/debops.cfg can alteady be used that way?

@htgoebel
Copy link
Contributor

htgoebel commented Jun 1, 2015

Re: debops/debops#117 (comment)

  1. This is another topic! Please do not mix issues, this makes following them hard.
  2. This is already addressed in Look for global debops.cfg in /etc #96, which was opened by yourself..

@antoineco
Copy link

antoineco commented Sep 7, 2016

Same thing happening to me right now on OS X, while I saw no issue on Linux.

ansible.cfg

[defaults]
lookup_plugins = "/Users/acotten/git/gini/aco/ansible-lab/ansible/lookup_plugins":"/Users/acotten/Library/Application Support/debops/debops-playbooks/playbooks/lookup_plugins":"/usr/share/ansible/lookup_plugins"
❯❯❯ ls -l "/Users/acotten/Library/Application Support/debops/debops-playbooks/playbooks/lookup_plugins"                                                                                                   aws-internal
total 88
-rw-r--r--  1 acotten  staff  5689 Jun 27 12:18 file_src.py
-rw-r--r--  1 acotten  staff  2142 Jun 27 12:18 lists.py
-rw-r--r--  1 acotten  staff  5689 Jun 27 12:18 task_src.py
-rw-r--r--  1 acotten  staff  5713 Jun 27 12:18 template_src.py

I call debops.auth from a custom playbook like this:

---

# Cherry-pick of DebOps roles

- name: Common configuration for all hosts
  hosts: [ 'debops_all_hosts', '!debops_no_common' ]
  become: True

  roles:

    - role: debops.core
      tags: [ 'role::core' ]

    - role: debops.sysctl
      tags: [ 'role::sysctl' ]

    - role: debops.auth
      tags: [ 'role::auth' ]

    - role: debops.users
      tags: [ 'role::users' ]

Playbook execution:

TASK [debops.auth : DebOps pre_tasks hook] *************************************
fatal: [ec2-1-2-3-4.eu-central-1.compute.amazonaws.com]: FAILED! =>
{ "failed": true,
  "msg": "lookup plugin (task_src) not found"
}

Thanks for the tip @drybjed and @carlalexander, symlinking /Users/acotten/Library/Application Support/debops/debops-playbooks/playbooks/lookup_plugins to /usr/share/ansible/lookup_plugins works but it is not trivial at all on OS X El Capitan.

@antoineco
Copy link

edit: actually changing the lookup_plugins parameter does not help.

ansible.cfg

[defaults]
lookup_plugins = "/tmp/lookup_plugins"

The error still shows up after copying the DebOps lookup_plugins directory to /tmp.

@htgoebel
Copy link
Contributor

htgoebel commented Sep 8, 2016

Please note that the ansible.cfg file gets overwritten on every start of a debops.

You'll have to add this into .debos.cfg like this.

[ansible defaults]
lookup_plugins = "/tmp/lookup_plugins"

This will be prepended to the paths debos generates automatically. For more details, please see the manual.

@antoineco
Copy link

antoineco commented Sep 8, 2016

@htgoebel yes, that's what I did, but on OS X the space in the path doesn't seem to be the issue anymore (I'm using Ansible 2.1.1.0).

I'm suspecting an issue when including DebOps roles in custom playbooks, since debops -t role::auth works absolutely fine while debops custom_playbook -t role::auth doesn't.

No issue on Linux.

@antoineco
Copy link

I can confirm that the playbook location is the issue. Check this out:

playbook in local project tree (project/ansible/playbooks/):

❯❯❯ debops site_custom -i ansible/inventory/internal -t role::auth
...
TASK [debops.auth : DebOps pre_tasks hook] *************************************
fatal: [ip-172-31-59-175.eu-central-1.compute.internal]: FAILED! => {"failed": true, "msg": "lookup plugin (task_src) not found"}

same playbook moved to DebOps tree (~/.../debops/debops-playbooks/playbooks/)

❯❯❯ debops site_custom -i ansible/inventory/internal -t role::auth
...
TASK [debops.auth : DebOps pre_tasks hook] *************************************

TASK [debops.auth : Install auth-related packages] *****************************
ok: [ip-172-31-59-175.eu-central-1.compute.internal] => (item=[u'sudo', u'libpam-cracklib'])

@antoineco
Copy link

antoineco commented Sep 12, 2016

@htgoebel @drybjed Aha! The issue on OS X is actually caused by the quotes inside the ansible.cfg file!

This fails:
lookup_plugins = "/Users/acotten/git/gini/aco/ansible-playbooks-debops/ansible/lookup_plugins":"/Users/acotten/Library/Application Support/debops/debops-playbooks/playbooks/lookup_plugins":"/usr/share/ansible/lookup_plugins"

While this works:
lookup_plugins = /Users/acotten/git/gini/aco/ansible-playbooks-debops/ansible/lookup_plugins:/Users/acotten/Library/Application Support/debops/debops-playbooks/playbooks/lookup_plugins:/usr/share/ansible/lookup_plugins

I'm using the zsh v5.2 shell and Ansible 2.1.1.0.

@htgoebel
Copy link
Contributor

Well, the raw value is taken from .debops.cfg and prepended uninterpreted into ansible.cfg.

So I consider this solved.

@antoineco
Copy link

@htgoebel my .debops.cfg file is completely untouched, which means out-of-the-box all DebOps roles using lookup plugins are broken on OS X.

@SatWiz
Copy link

SatWiz commented Nov 3, 2016

using: zsh 5.2, ansible 2.1.2.0
@antoineco how do I get rid of the quotes for lookup_plugins in the ansible.cfg file while it is overwritten during runtime?

@antoineco
Copy link

@SatWiz you have to

  1. Copy the value of the auto-generated lookup_plugings setting in the project's ansible.cfg file
  2. Remove all the quotes from it
  3. Add the value without the quotes to the project's .debops.cfg file
  4. Let DebOps regenerate the ansible.cfg file

This works well as long as you're the only user executing the playbooks. If not it might get trickier to manage because the path to the local DebOps playbooks is user specific.

@SatWiz
Copy link

SatWiz commented Nov 3, 2016

Thanks @antoineco for your explanations but it did not work out for me. At the end my ansible.cfg files is back again quoted with all of .debops.cf added in front of the variables.
Are you using a particular options to generate?

A bit strange is than some variables are generated without quotes like hostfile, roles_path and library.

@htgoebel
Copy link
Contributor

htgoebel commented Nov 3, 2016

The quotes are added for ansible >= 1.7 since fe61193 "Add work-around for ansible's buggy handling of paths containing spaces."

@antoineco
Copy link

@SatWiz I actually edited my ansible.cfg manually and stopped using the DebOps wrapper altogether as a workaround.

I have a feeling this issue is specific to the Zshell though (which I am also using) but I can't confirm right now. Have you tried from a Bash shell?

@SatWiz
Copy link

SatWiz commented Nov 3, 2016

@antoineco, bash is having the same issue.
TASK [debops.postfix : DebOps pre_tasks hook] ********************************** fatal: [smtp]: FAILED! => {"failed": true, "msg": "lookup plugin (task_src) not found"}

@htgoebel it works for me without complaining about the plugin when reverting the changes in fe61193.
But now other issue occurs, maybe it is my custom playbook. Need to dig further.

TASK [debops.postfix : DebOps pre_tasks hook] ********************************** An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named debops fatal: [smtp]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}

@SatWiz
Copy link

SatWiz commented Nov 3, 2016

@htgoebel is there a simple test to check the plugins is loaded correctly?

@SatWiz
Copy link

SatWiz commented Nov 19, 2016

runs smoothly with osx now by reinstall ansible with pip install ansible.
First clear previous version installed with brew

@NickVolynkin
Copy link

NickVolynkin commented Jun 20, 2017

Fixed by reinstalling ansible with pip as @SatWiz suggested and adding this to ansible.cfg:

[defaults]
lookup_plugins = ~/Library/Application Support/debops/debops-playbooks/playbooks/lookup_plugins:/usr/share/ansible/lookup_plugins

@NickVolynkin
Copy link

NickVolynkin commented Jun 20, 2017

@drybjed looks like some roles depend on the task_src plugin but do not list it as a dependency. For example, running ansible-nginx requires installing the full debops package.

It seams reasonable to me to explicitly state this dependency. Also, is there a way to obtain the lookup plugins without installing debops? I've looked through the debops-tools and debops-playbooks but with no success.

@drybjed
Copy link
Member

drybjed commented Jun 20, 2017

The lookup plugins can be found in the debops-playbooks repository, here.

I suppose that this could be explained briefly in the documentation of each role that uses the custom lookups.

@NickVolynkin
Copy link

@drybjed thanks, I see it now. What is the right way to install debops-playbooks without the whole debops package?

@drybjed
Copy link
Member

drybjed commented Jun 20, 2017

You could just clone it somewhere, it's just a git repository. The debops scripts expect it in a specific location in a filesystem, but if you don't plan to use them you can put it wherever you want.

@pbauer
Copy link

pbauer commented Nov 30, 2017

I ran into the same issue and I fixed it by setting data-home in my projects .debops.cfg as described in https://docs.debops.org/en/latest/debops-tools/docs/configuration.html#the-paths-section:

[paths]
data-home = ~/.local/share/debops

Now debops-update installs the monorepo there and everything is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants