0
- name: installing dependencies
  yum:
    name: "{{ item }}"
    state: present
  with_items:
  - gcc
  - glibc
  - glibc-common
  - gd
  - gd-devel
  - make
  - net-snmp
  - libselinux-python

- name: adding group
  group:
    name: nagcmd
    state: present

- name: adding user
  user:
   name: nagios
   state: present
   group: nagcmd

- name: downloading nagios plugin
  unarchive:
    src: "{{ item }}"
    dest: /tmp
    remote_src: yes
 with_items:
  - http://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.2.0/nagios-4.2.0.tar.gz
  - https://www.nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

- name: changing directory and installing nagios
  command: '"{{ item }}" chdir /tmp/nagios-4.2.0'
  with_items:
      - ./configure --with-command-group=nagcmd

- name: changing directory and installing nagios
  command: '"{{ item }}" chdir /tmp/nagios-4.2.0'
  with_items:
      - make all
- name: changing directory and installing nagios
  command: '"{{ item }}" chdir /tmp/nagios-4.2.0'
  with_items:
       - make install

While ruuning this playbook iam getting the following error.

TASK [nagios : changing directory and installing nagios] ***********************
failed: [52.172.55.94] (item=./configure --with-command-group=nagcmd) => {"changed": false, "cmd": "'./configure --with-command-group=nagcmd' chdir /tmp/nagios-4.2.0", "failed": true, "item": "./configure --with-command-group=nagcmd", "msg": "[Errno 2] No such file or directory", "rc": 2}

How to run ./compile make and make install commands using ansible?Pls help.

Jenny D
  • 27,780
  • 21
  • 75
  • 114
arun mohan
  • 183
  • 2
  • 2
  • 9

2 Answers2

1

If you run it like that, if one of the tasks fail, it will still continue to the next task.

In order to avoid it, try:

- name: changing directory and installing nagios
  command: '"{{ item }}" chdir /tmp/nagios-4.2.0'
  with_items:
    - ./configure --with-command-group=nagcmd && make all && make install

Edit #1:

Ok I think I know how to solve it, change the "command:" directive to "shell", now your playbook should looks like so:

- name: changing directory and installing nagios
  shell: "{{ item }}"
  args:
    chdir: "/tmp/nagios-4.2.0"
  with_items:
    - ./configure --with-command-group=nagcmd 
    - make all
    - make install
Itai Ganot
  • 10,644
  • 29
  • 93
  • 146
0
- name: installing dependencies
  yum:
    name: "{{ item }}"
    state: present
  with_items:
  - gcc
  - glibc
  - glibc-common
  - gd
  - gd-devel
  - make
  - net-snmp
  - libselinux-python
  - unzip
  - httpd
- name: adding group
  group:
    name: nagios
    state: present

- name: adding user
  user:
   name: nagios
   state: present
   group: nagios

- name: downloading nagios plugin
  unarchive:
    src: "{{ item }}"
    dest: /tmp
    remote_src: yes
  with_items:
  - http://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.2.0/nagios-4.2.0.tar.gz
  - https://www.nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

- name: configure
  command: "./configure --with-command-group=nagios chdir=/tmp/nagios-4.2.0"

- name: make
  command: "make all chdir=/tmp/nagios-4.2.0"

- name: make install
  command: "make install chdir=/tmp/nagios-4.2.0"

- name: make install-init
  command: "make install-init chdir=/tmp/nagios-4.2.0"

- name: make install-commandmode
  command: "make install-commandmode chdir=/tmp/nagios-4.2.0"

- name: make install-config
  command: "make install-config chdir=/tmp/nagios-4.2.0"

In this way iam able to compile and install.But i want to use "{{ item }}" to make it idempotent..any way for that?Pls help

arun mohan
  • 183
  • 2
  • 2
  • 9