Ошибка при использовании команд для компиляции и установки nagios с использованием Ansible

- 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

При рутировании этого учебника я получаю следующая ошибка.

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}

Как запустить команды ./compile make и make install с помощью ansible? Пожалуйста, помогите.

0
задан 4 January 2018 в 12:08
2 ответа

Если вы запустите его таким образом, если одна из задач не удастся, она все равно перейдет к следующей задаче.

Чтобы избежать этого, попробуйте:

- 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

Редактировать # 1 :

Хорошо, я думаю, что знаю, как решить эту проблему, измените директиву "command:" на "shell", теперь ваша playbook должна выглядеть так:

- 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
1
ответ дан 4 December 2019 в 16:03
- 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"

Таким образом я могу скомпилировать и установить. Но я хочу использовать "{{item}}", чтобы сделать его идемпотентным .. любым способом для что? Пожалуйста, помогите

0
ответ дан 4 December 2019 в 16:03

Теги

Похожие вопросы