Ansible Playbook Task - make from source fail - cmake

I am having a strange issue that has driven me nuts for days - I'm hoping someone may be able to point me in the right direction. I am attempting run a simple playbook, download a git repository, and then build from source. In one of my playbooks, this works fine, but in my 2nd playbook, I get an error every time I attempt to run the make command.
Keeping it simple for brevity...
tasks:
- name: Set Python PATH
become: yes
shell: export PYTHONPATH=/usr/local/lib/python3/dist-packages
- name: Update bashrc with PYTHONPATH
lineinfile:
path: /home/vagrant/.bashrc
line: export PYTHONPATH=/usr/local/lib/python3/dist-packages
- name: cmake
become_user: vagrant
shell: cmake ..
args:
chdir: /home/vagrant/application/build
This works fine, though I had to become_user: vagrant, even though I did not in my other playbook. (I've split the cmake, make, make install commands up for troubleshooting) Then I run:
- name: make
become_user: vagrant
shell: make
args:
chdir: /home/vagrant/application/build
This fails every time with a VERY large amount of red text. I have logged in to the target, and can run make successfully there. But cannot via Ansible.
I have tried the community make plugin, I have tried many variations of this, including become: yes, but get the errors every time. This is the beginning of the error:
fatal: [server.local]: FAILED! => {"changed": true, "cmd": ["make", "all"], "delta": "0:00:01.218515", "end": "2021-12-30 16:39:36.586928", "msg": "non-zero return code", "rc": 2, "start": "2021-12-30 16:39:35.368413", "stderr": "ERROR:gnuradio.grc.core.FlowGraph:Failed to evaluate variable block variable_ax25_decoder_0_0\nTraceback (most recent call last):\n File \"/usr/lib/python3/dist-packages/gnuradio/grc/core/FlowGraph.py\", line 227, in renew_namespace\n
Do you have any suggestions as to why MAKE would fail in this instance, when it can run fine in another? (I've tried multiple VMs, new installs etc) but am having no joy.

Related

Installing Xfce on CentOS 7 via ansible yum

I have a Centos 7 machine freshly started from the centos/7 vagrant base box. I provision the box via ansible but the following does not work:
- name: Install xfce
yum:
name: "#^Xfce"
state: present
enablerepo: "epel"
The error is:
TASK [desktop : Install xfce]
************************************************** fatal: [xxx]: FAILED! => {"changed": false,
"changes": {"installed": ["#^Xfce"]}, "msg": "Error: Nothing to do\n",
"rc": 1, "results": ["Loaded plugins: fastestmirror\nLoading mirror
speeds from cached hostfile\n * base: mirror.ratiokontakt.de\n * epel:
mirror.de.leaseweb.net\n * extras: centos.schlundtech.de\n * updates:
centos.schlundtech.de\nGroup Xfce does not exist.\n"]}
Yet, running the following command from within the machine works:
sudo yum --enablerepo=epel -y groups install "Xfce"
What am I doing wrong?
According to the yum module documentation:
Yum itself has two types of groups. “Package groups” are specified in the rpm itself while “environment groups” are specified in a separate file (usually by the distribution). Unfortunately, this division becomes apparent to ansible users because ansible needs to operate on the group of packages in a single transaction and yum requires groups to be specified in different ways when used in that way. Package groups are specified as “#development-tools” and environment groups are “#^gnome-desktop-environment”. Use the “yum group list hidden ids” command to see which category of group the group you want to install falls into.
You're specifying your grouop as #^Xfce, which is the syntax for an "environment group", but if you look at the output of yum group list hidden ids there is no "Xfce" environment group. There is a package group by that name, and this playbook seems to install it successfully:
---
- hosts: localhost
gather_facts: false
tasks:
- name: install xfce
yum:
name: "#Xfce"
state: "present"
enablerepo: "epel"

Ansible not picking up custom module

I'm having issues with Ansible picking up a module that I've added.
The module is called 'passwordstore' https://github.com/morphje/ansible_pass_lookup/.
I'm using Ansible 2.2
In my playbook, I've added a 'library' folder and have added the contents of that GitHub directory to that folder. I've also tried uncommenting library = /usr/share/ansible/modules and adding the module files there and still doesn't get picked up.
Have also tried setting environment variable to ANSIBLE_LIBRARY=/usr/share/ansible/modules
My Ansible playbook looks like this:
---
- name: example play
hosts: all
gather_facts: false
tasks:
- name: set password
debug: msg="{{ lookup('passwordstore', 'files/test create=true')}}"
And when I run this I get this error;
ansible-playbook main.yml
PLAY [example play] ******************************************************
TASK [set password] ************************************************************
fatal: [backend.example.name]: FAILED! => {"failed": true, "msg": "lookup plugin (passwordstore) not found"}
fatal: [mastery.example.name]: FAILED! => {"failed": true, "msg": "lookup plugin (passwordstore) not found"}
to retry, use: --limit #/etc/ansible/roles/test-role/main.retry
Any guidance on what I'm missing? It may just be the way in which I'm trying to add the custom module, but any guidance would be appreciated.
It's a lookup plugin (not a module), so it should go into a directory named lookup_plugins (not library).
Alternatively, add the path to the cloned repository in ansible.cfg using the lookup-plugins setting.

Shared connection to server failed (trying to run an Ansible playbook)

I am quite new to SSH servers and Ansible so this might be a dumb question.
Tried to run an Ansible playbook whilst accessing the server with a private key using the bash command below.
ansible-playbook dbserv.yml -i hosts --limit local-servers --private-key=(where I put the private key)
However, I am getting this error:
fatal: [xxx]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "setup"
},
"module_stderr": "Shared connection to xxx closed.\r\n",
"module_stdout": "/bin/sh: 1: /usr/bin/python2.7: not found\r\n",
"msg": "MODULE FAILURE" }
I have Python installed on my computer so I do not understand why I am getting this error.
OS environment:
Ubuntu 16.04.1
The error message you get is:
/usr/bin/python2.7: not found
Ansible requires the target machine to have Python installed in order to work properly (see Managed node requirements).
The most likely reason is that your target is Ubuntu 16.04 which does not come with Python 2 installed. In this case you need to install it or try the experimental support for Python 3.
If Python 2.7 is installed in a different directory, you can add a host variable, for example in your inventory file (assuming the hostname is xxx as in your question`):
xxx ansible_python_interpreter=/path/to/python2.7
To run modules with Python 3 (experimental), set:
xxx ansible_python_interpreter=/usr/bin/python3
Note: Ansible by default looks for /usr/bin/python, so it's likely that your playbook, inventory file, or ansible.cfg already contain settings for /usr/bin/python2.7 which does not exist on the target machine.

Overriding Ansible module options defaults

I'm struggling to find out how to override Ansible module options defaults without hand rolling it with variables. Even better if there would be a way to override module options defaults only for a subset of hosts.
Say on couple hosts Git is available at /bin/git, as expected. On couple other hosts Git is at /usr/local/bin/git. How can I override the git module executable option default for the latter group of hosts?
At the moment I'm setting a hosts group variable like:
git_executable=/usr/local/bin/git
and using it with default(omit) filter everywhere git is used like so:
- git: "executable={{git_executable|default(omit)}} ..."
So it gets properly overriden on hosts where it's defined, and ignored on others.
executable may not be the best example here, since that may be controlled with PATH environment variable or something. So what about any kind of module option in general that I'd like to override for just some hosts but otherwise fall back to module default?
Since there is couple more of such basic differences in this environment, it's quite tedious to sprinkle this kind of default lookup using variables all over the place just in case it gets run on a host with non-default setup. Is there a way to do this better?
I don't think there is a better option. Modules only know what you pass to them. They do not have access to global vars, server facts or anything else unless you explicitly pass it as a module parameter.
If this really really is important and you want to invest some time, you could create your own action plugin(s). Action plugins are local actions, therefore have access to the Ansible runnerc class and all its properties including facts etc. So you could handle the default parameters or executable detection in there based on server facts and then call the git or whatever module programatically. Huge overhead in my opinion but that depends on view and might be feasible on your end.
Though take care, action plugins are 100% undocumented. Ansible 2.0 is going to be released in the next days. They claim 100% backwards compatibility but I wouldn't be surprised if that only counts for documented features.
In this specific case git.executable as long as it's in PATH or '/sbin', '/usr/sbin', '/usr/local/sbin' git module would find it because it uses the basic.get_bin_path()
On the larger topic, personally I would go with what you already did. But if you are bent on it one other possible hack would be to [mis]use the include statement to create a wrapper for each module that supplies the default value you want from some variable.
Obviously you would have to specify the path somewhere yourself either in group_vars or host/role/... vars. Or a variable defined in the play's vars section.
$ cat my_echo.yml
- shell: "{{echo_exec}} '{{text}}'"
$ cat playbook.yml
- hosts: localhost
tags: so
gather_facts: False
vars:
echo_exec: echo
tasks:
- include: my_echo.yml text='some text'
changed_when: False
- hosts: localhost
tags: so
gather_facts: False
vars:
echo_exec: printf
tasks:
- include: my_echo.yml text='some text'
changed_when: False
$ ansible-playbook playbook.yml -t so -v
PLAY [localhost] **************************************************************
TASK: [shell {{echo_exec}} '{{text}}'] ****************************************
changed: [localhost] => {"changed": true, "cmd": "echo 'some text'", "delta": "0:00:00.003782", "end": "2015-03-20 17:45:58.352069", "rc": 0, "start": "2015-03-20 17:45:58.348287", "stderr": "", "stdout": "some text", "warnings": []}
PLAY [localhost] **************************************************************
TASK: [shell {{echo_exec}} '{{text}}'] ****************************************
changed: [localhost] => {"changed": true, "cmd": "printf 'some text'", "delta": "0:00:00.003705", "end": "2015-03-20 17:45:58.690657", "rc": 0, "start": "2015-03-20 17:45:58.686952", "stderr": "", "stdout": "some text", "warnings": []}
PLAY RECAP ********************************************************************
localhost : ok=2 changed=2 unreachable=0 failed=0
$

Ansible error change handler is not defined

I'm trying to run my first playbook to install Java on four servers and subsequently define a JAVA_HOME environment variable.
ansible-playbook site.yml --check
PLAY [crave_servers] **********************************************************
GATHERING FACTS ***************************************************************
ok: [54.174.151.196]
ok: [54.174.197.35]
ok: [54.174.207.83]
ok: [54.174.208.240]
TASK: [java | install Java JDK] ***********************************************
changed: [54.174.197.35]
changed: [54.174.151.196]
changed: [54.174.208.240]
changed: [54.174.207.83]
ERROR: change handler (setvars) is not defined
I've placed my site.yml under /etc/ansible
---
- hosts: crave_servers
remote_user: ubuntu
sudo: yes
roles:
- java
I've placed main.yml under /etc/ansible/java/tasks
---
- name: install Java JDK
apt: name=default-jdk state=present
notify:
- setvars
I've placed main.yml under /etc/ansible/handlers
---
- name: setvars
shell: echo "JAVA_HOME=\"/usr/lib/jvm/java-7-openjdk-amd64\"" >> /etc/environment
Now I'm not sure if the syntax is structure of my handlers is correct. But it's obvious from the output that Ansible is able to find the correct role and execute the correct task. But the task can't find the handler.
Nobody else seems to have the same problem. And I don't really know how to debug it because my ansible version seems to be missing the config file.
You should put your handler to /etc/ansible/java/handlers/main.yml
As handlers are part of a role.
Remarks:
You should not use your handler as it would paste the line into /etc/environment each time you call this playbook. I would recommend the lineinefile module.
You should reconsider your decision to put ansible playbooks into /etc