How to download and install ansible modules? - ansible

I have found this DNSimple ansible module:
http://docs.ansible.com/ansible/dnsimple_module.html
but can not find anywhere on that page to download and install it? How do I go about downloading and installing ansible modules like this. Thanks.

The accepted answer solved the questioner's problem but didn't address the broader scope of the question.
How to install an Ansible module? The documentation is currently vague as to how to achieve this simple requirement!
An excellent general guide to writing modules (I've no connection to the author) can be found here.
The quickest way is to simply have a folder called library/ in the same folder as your playbook. Inside this folder, place the python script for the Ansible Module. You should now have a corresponding task available to your playbook.
If you want to share your module across multiple projects, then you can add an entry to /etc/ansible/ansible.cfg pointing to a shared library location, eg:
library = /usr/share/ansible/library

The module itself is part of ansible since version 1.6 (as stated here). To use it, you need to have dnsimple on your host machine (also stated in the above description). Install it with sudo pip install dnsimple

It is important to know that base ansible modules are not installed by default on devel version, which is the default installed version when you build from source.
Only few modules are present for developpment purpose.
So when you'll run your playbook it'll complain about not found module with following error message
couldn't resolve module/action 'xxx'
If you have no choice but building for source, don't forget to checkout the stable branch to install all basic ansible modules!

Related

go install github.com/dmacvicar/terraform-provider-libvirt#latest - shows error

I am trying to Provision VMs on KVM with Terraform.
one of the steps in installations is to download and install the provider buy the command:
go install github.com/dmacvicar/terraform-provider-libvirt#latest
but it errors:
The go.mod file for the module providing named packages contains one or
more replace directives. It must not contain directives that would cause it to be interpreted differently than if it were the main module.
I didn't find a solution, is someone has faced it?
thank you
As JimB notice in comments:
If there are replace or exclude directives in the module, the correct
installation method is to clone the source and install it,
git clone github.com/dmacvicar/terraform-provider-libvirt
cd terraform-provider-libvirt
go install

Correct way to setup the environment when developing custom ansible modules that use 3rd party python libraries

I have developed a custom ansible module that has a dependency on a 3rd party library PyYAML. However running the playbook yields
ansible_module_my_module.py, line 5, in <module>
import yaml
ImportError: No module named yaml
I see PyYAML in the ansible requirements.txt (https://github.com/ansible/ansible/blob/stable-2.8/requirements.txt) so I know its installed/used on the host machine. I'm wondering if there is a recommended way to install it on the remote machine?
I can add a step in the playbook using the pip ansible module to install it on the remote. Something like
- hosts: all
tasks:
- name: Installing PyYAML python library using Ansible pip module
pip:
name: PyYAML
But that means the playbook knows implementation details about modules buried deep down the stack which seems wrong. My expectation is that there is some way to tell ansible to install the 3rd party libraries on the remote machine as part of its setup. For example adding a requirements.txt in my module and ansible appends it to its setup, but I can't seem to find an elegant way to do it. Any help is appreciated.
First ansible detecting dependencies and automatically installing it is against their philosophy of installing as little as possible on hosts. To get around that I ended up wrapping my custom module in a role and passing variables to that role instead of directly to the module. So users set role variables and call it using include_role and tasks_from after including it in their requirements.yml. Then I used the pip module (https://docs.ansible.com/ansible/latest/modules/pip_module.html) to setup the environment as a task in the role before the task that calls my custom module.
The second issue I faced was that ansible will default to the /usr/bin/python even when executed via a virtualenv. This is, apparently designed behavior. To get around that I had to include ansible_python_interpreter to manually set it to the virtualenv when running locally.

How to use a class from a module immediately after installing it with Puppet?

I am experimenting with Puppet using Vagrant. I'm new to Puppet.
I'm installing modules in my Puppet manifest using the approach suggested at: Can I install puppet modules through puppet manifest?
My default.pp contains something like:
$dsesterojava = 'dsestero-java'
exec { 'dsestero-java':
command => "puppet module install ${dsesterojava}",
unless => "puppet module list | grep ${dsesterojava}",
path => ['/usr/bin', '/bin']
}
include java::java_7
I'm trying to import a module and then immediately use the classes defined in it.
Currently, I get:
Error: Could not find class java::java_7
If I comment out the include line and re-run it. The module installs. If I then removed the comment and run the provisioning again then it works.
There is some kind of "chicken and egg" situation here. Can I use a module in the same Puppet manifest that installs it?
How should I solve it?
No, you cannot do this. When your catalog is compiled, Puppet will search in the appropriate directories for all of the required code and data. Since the java module does not exist until catalog application, the compilation of a catalog (occurs prior to application) depending upon it will fail. You are absolutely dealing with a "chicken and egg" situation here. I highly recommend against using Puppet code to install Puppet code.
Alternatively, the recommended approach to install and manage your Puppet modules is to use one of these solutions:
librarian-puppet: http://librarian-puppet.com/
r10k: https://github.com/puppetlabs/r10k
code-manager (PE only): https://puppet.com/docs/pe/2017.3/code_management/code_mgr.html
These will also solve the problem for you within the Vagrant if you are using the agent provisioner and subscribing the Vagrant instance to a Puppet Master.
If you are using the apply provisioner inside of Vagrant, then you will need to go a different route. The simplest solution is to use the shell provisioner to install Puppet modules via module install after the Puppet installation (unless you are using a Vagrant box with Puppet baked in, in which case you are probably not installing Puppet on it). Alternatively, you could share a directory with the host where your modules are installed, or install the librarian-puppet or r10k gems onto the Vagrant box and then use them to install into the appropriate path. I can go into more detail on these upon request.

Ansible Composer Module Missing?

When I try to use the Ansible's Composer module and paste the following task into my playbook.yml file I get an error.
playbook.yml
- name: Composer Install Site Dependencies
composer: command=install working_dir=/var/www/html
Error:
ERROR: composer is not a legal parameter in an Ansible task or handler
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
After some investigation I ran "anisble-doc --list" on the command line to see the available modules and "composer" is not listed. I am running Ansible version 1.5.4, do I have to add it separately?
As #user272735 indicated in the comments, this is an unreleased module- it's slated for the 1.6 release, which is under "active development". (admittedly it was originally slated for 1.4) You have a couple of options:
install ansible from the bleeding edge. See "running from source". (obviously, this is scary)
ninja-patch the file into your locally installed tree. (obviously, this is scary)
add the file into your local Ansible repo.
As "developing modules" says, a fourth option is to specify your library path via ANSIBLE_LIBRARY or --module-path. HOWEVER, this overrides your global library/module path. That isn't what you want to do unless you are providing every module.
adding into your repo
I'm assuming your repo is named "ansible" and is set up properly, like this:
ansible/
ansible/roles/
ansible/group_vars/
In that case, simply add a library directory at the top (the 'best practices' discusses this but not in the expected section):
ansible/
ansible/roles/
ansible/group_vars/
ansible/library/
Inside there, add the composer file in there. That makes its path/file the following:
ansible/library/composer
Note it is not composer.py or anything else. Also, it doesn't seem to need the +x bit, so no fussy worries there.
Once you do that, you can run Ansible commands as you'd expect. The composer module will simply be there.

chef mysql install specific version

I want to install mysql v5.5.27 and php v5.3.15 but opscode doesn't show how to do this.
I've checked the recipes and saw the attributes and modified them but still no results.
Is there a way to force this?
Thanks in advance!
For PHP, if you want to install a different version from what is what is available in the distribution's official repository, you can use the compile from source install method instead of package (default).
Simply change default['php']['install_method'] to 'source' and run the default recipe. Alternatively explicitly run php::source ;-)
NOTE: You also need to change the default['php']['url'], default['php']['version'], default['php']['checksum'], etc to suite your needs.
For MySQL, as Mark said, it is up to the distribution (the version from its repository), looking at the mysql::server there isn't easy way to change it, as there is no such option as PHP (install by compiling from source) like the PHP cookbook.
The cookbook only has logic for choosing the version when installing on windows. On Linux the cookbook simply installs the mysql package supported by the package repositories associated with your distro.

Resources