Ansible - adding parameters for rpm - ansible

I am beginner using Ansible and I am using some rpm to be installed on my target machine with yum as the package manager. I am getting an error saying the package conflicts with some files on the system. When I saw for the error on the net, I found that adding the following parameter "--replacefiles" solves my problem.
But, I am not sure how to specify this parameter to the ansible playbook. Any help is appreciated.

That's not supported by the yum module. You will need to call yum per shell or command module to use it with that param.

Related

Difference between ansible yum list?

I am trying to output a list of installed yum packages before and after running the yum update command in ansible. However, I note that for the list parameter, there are other options such as installed, updates, available and repos. May I know what is the difference between these options?
Is making reference to the options avaialble in the "yum" package managenent. So easier way to know the difference is by referencing to "yum" documentation itself (or man page), as "yum" ansible module only uses its capabilities.
list - As ansible module doc explains, it is the equivalent to "yum list --show-duplicates "
installed - Will list the yum installed packages in the host
updates - Will return a list with the packages to be updated
available - Lists available packages.
repos - Will list the subscribed repos for the host.
You can always see the difference by yourself even using ad-hoc commands and visually exploring the output, like this.
ansible kube_workers -m yum -a 'list=repos'
Hope that helped.

Ansible pass value to installation commandline gui

How do I pass value to the commandline-gui prompt?
Like I typically install LAMP on a fresh Ubuntu using the following command.
sudo apt-get install lamp-server^ phpmyadmin
And during install I am asked for a few inputs as below
So how do I pass/input values from a playbook?
When using Ansible, you would generally install the packages non-interactively, like this [1]:
- command: apt-get -y install lamp-server^ phpmyadmin
environment:
DEBIAN_FRONTEND: noninteractive
This will suppress any interactive configuration prompts during the
install. You can then perform configuration tasks after the fact using
Ansible, either by directly manipulating files etc. or by using the
debconf module.
If you're not familiar with debconf, this question has some information about interacting with the package configuration system.
[1] Actually, you would more often use the package module, but that doesn't support package groups like lamp-server^.

ansible module actions without install

I'm writing an Ansible playbook to configure new machines for our developing environment.
If I want to install postgresql using homebrew, I would use Ansible's given homebrew model to achieve this task.
But before I run this task, should I have a task that will install homebrew first?
If this is the case, how can I install homebrew using the command or shell Ansible module, which will normally prompt for a user input during the process of installation?
Yes, you have to install Homebrew first. The homebrew Ansible module documentation is not clear about that; if you check its source code it fails if it can’t find Homebrew and it doesn’t try to install it for you.
There already are answers on how to bypass the prompt in Homebrew’s install script. There are also other ways of installing Homebrew like downloading it as a tarball and un-taring it somewhere (which you can do with the unarchive Ansible module) or cloning its source code using git.

Is it safe to use ansible's package module to upgrade all packages?

I have a numer of ansible playbooks I use to perform certain actions on Debian and CentOS VMs. Until now, when I needed to handle packages I would use ansible modules apt and yum. Consequently, I had to check which OS was installed and then use the correct ansible module.
However, I've recently learned there's a module called package which somehow unifies package managers, reducing playbook's complexity, so I'm now trying to use this module only.
One of the operations I want to perform is to update all packages. The problem is that ansible's documentation doesn't say how to do this using package. It does say, however, how to do it with apt and yum: the first one uses and upgrade operation and the latter suggests writing something like:
yum: name=* state=latest
For this reason I thought I could use package to do the following:
package: name=* state=latest
When I ran this playbook I didn't come across any error but this isn't documented anywhere and apt and yum don't work exactly the same way. So my question is: is the command above a safe one as in does it actually do what I want it to do?
Thanks in advance!
EDIT:
I have found out that using package: name=* state=latest will try to install or update all available packages instead of just updating installed ones. Therefore this isn't a valid solution for me. Alternatively, I can keep using yum and apt for this particular action, but I do wonder why is it not possible to do this using package, or if I'm missing something.
Well after further testing I can now answer the question by myself, and the answer is no. Using package: name=* state=latest on a Debian machine will try to install or update every package available in the repositories, so it can't be used as a replacement for an apt-get upgrade.
From the docs below i think its clear that the use you are describing can be considered safe.
From package documentation:
This module actually calls the pertinent package modules for each system (apt, yum, etc).
So whatever you pass to it should be supported by the underlined packagers yum or apt.
From apt documentation:
Name wildcards (fnmatch) like apt* and version wildcards like foo=1.0* are also supported.
From yum->name documentation:
When using state=latest, this can be '*' which means run: yum -y update.
EDIT: After #Xavier Alvarez testing the apt: name=* state=latest will install all packages in repo.

How to create lxc containers in ubuntu 14.04 using Ansible module?

I am trying to create a lxc container by using lxc_container module provided by ansible. Can someone tell me the exact playbook task which will just create the lxc container ?
Based on the response in the comments above and your duplicate question.
It would appear that your issue is caused by not having the module lxc-python2 installed.
I'm also assuming there's other errors which your are overlooking in your posts and debugging efforts. So the steps to apply are as follows:
sudo apt-get install python-pip
pip install lxc-python2
read any error output carefully.

Resources