I am trying to install jq on mac using ansible-playbook. I have used Macports module available in ansible to achieve this task
Playbook-snippet
- name: install items
macports:
name: "{{ item }}"
state: present
with_items:
- jq
- openjdk11
- nodejs12
- git
When I run this playbook the play is success and when I check for jq installation using command "jq --version" seeing command not found error, whereas other items like git and java are installed. Facing this issue only for nodejs and jq.
Can anyone help me on this?
It sounds like you have failed to include the macports directory in your PATH, since macOS ships with a git binary (although it's usually just a shim to install the Xcode Command Line Tools), and likely the same story with java
Of course, since your question didn't include one byte of output or troubleshooting text, it's just a theory
Related
Suppose I have the following ansible yum task
- name: install java-1.8.0
yum:
name: java-1.8.0-openjdk
state: latest
Now, yum repo, is not the standard java repo, but local repo on site premises. Differently from standard ones, it contains java packages rpms for different architecture and os release in the same directory.
The behavior that we see is that this task tries to install java for centos8 on centos7 disregarding the architecture that it runs on.
for example instead of
java-1.8.0-openjdk-....el7_5.x86_64.rpm
it will take
java-1.8.0-openjdk-....el8_4.x86_64.rpm
though it running on el7
Is this desired behavior for this ansible yum module when running "latest" or is it bug?
I can gather a list of Ansible facts on my MacOS system locally, using the following command:
ansible -m setup localhost
However, this list of facts doesn't provide a list of Homebrew packages that are installed, apparently.
If I run this command, I don't get any extra information about installed Homebrew packages either:
ansible -m homebrew localhost
All I get is the following output:
localhost | SUCCESS => {
"changed": false,
"msg": ""
}
Question: How can I extend Ansible to gather a list of installed Homebrew packages as Ansible "facts"?
To solve this, I just learned how to create Ansible custom facts via this article.
The solution is painfully simple. I created the following custom Ansible fact file under the path /etc/ansible/facts.d/homebrew.fact, which worked flawlessly.
#!/usr/bin/env pwsh
brew list -1 | ConvertTo-Json
Make sure that you make the *.fact* files executable as well, otherwise they won't be called by Ansible.
sudo chmod +x /etc/ansible/facts.d/homebrew.fact
NOTE: Requires PowerShell to be installed. brew cask install powershell
I have recently reimaged my laptop with Ubuntu 18.04 and after installing Ansible(2.7.5) via PIP (python2) I have realised that /etc/ansible is missing.
Removing the package and reinstalling it has not changed anything. Apart from missing the /etc/ansible Ansible is working. Any idea how to force the creation of directory on the install?
Or shall I just create it manually?
Yes. You can create is manually. Or, you might want to take the one from the Ubuntu package (when there is a reason not to install it completely).
# dpkg -l | grep ansible
ii ansible 2.7.5-1ppa~bionic all
# apt-file list ansible | grep ansible.cfg
ansible: /etc/ansible/ansible.cfg
I can no longer install software using a list of items.
I've commented out git to see if it was the issue. It turns out nano will fail too.
My task:
- name: Install git, nano, curl, wget, unzip and mercurial
apt: name={{item}} state=installed
with_items:
# - git
- nano
- curl
- wget
- unzip
- mercurial
The error:
TASK [common : Install git, nano, curl, wget, unzip and mercurial] *************
failed: [local_vm] (item=[u'nano', u'curl', u'wget', u'unzip', u'mercurial']) => {"failed": true, "item": ["nano", "curl", "wget", "unzip", "mercurial"], "msg": "No package(s) matching '['nano'' available"}
A stab in the dark would be extra quotes perhaps?
From the console of my server:
me#server:~$ sudo apt-get install nano
Reading package lists... Done
Building dependency tree
Reading state information... Done
nano is already the newest version (2.5.3-2ubuntu2)
I'm running Ansible 2.2.0
Update #1
Python 2.7.6 on client, Python 2.7.12 on server.
Update #2
Either I got betrayed by the Windows Linux Subsystem or Ansible 2.2.0 is the issue. I tried on another VM (CentOS 7) where Ansible 2.3 is installed and the same script went through fine.
The problem is with items squashing for package modules.
If you can't update Ansible version, use ANSIBLE_SQUASH_ACTIONS=[] environment variables as a workaround.
It will increase execution time for apt module (because it will be executed for every item separately), but will not try to join items into single call.
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.