Ansible ролей ошибок YAML - PullRequest
       0

Ansible ролей ошибок YAML

0 голосов
/ 29 февраля 2020

Я пытаюсь выполнить это

curl -X PUT 192.168.1.11:9200/_cluster/settings?pretty -H 'Content-Type: application/json' -d'{"persistent": {"cluster.routing.allocation.enable": "primaries"}}'

И когда я делаю это прямо из оболочки, это дает мне правильный вывод

curl -X PUT 192.168.1.11:9200/_cluster/settings?pretty -H 'Content-Type: application/json' -d'{"persistent": {"cluster.routing.allocation.enable": "primaries"}}'
{
  "acknowledged" : true,
  "persistent" : {
    "cluster" : {
      "routing" : {
        "allocation" : {
          "enable" : "primaries"
        }
      }
    }
  },
  "transient" : { }
}

и вот мой ansible задача оболочки

- name: Turn off shard reallocation
  shell: "curl -X PUT 192.168.1.11:9200/_cluster/settings?pretty -H 'Content-Type: application/json' -d'{"persistent": {"cluster.routing.allocation.enable": "primaries"}}'" 
  register: response
  failed_when: response.stdout.find('"acknowledged":true') == -1

и выполняется с ошибкой

ERROR! Syntax Error while loading YAML.
  did not find expected key

The offending line appears to be:

- name: Turn off shard reallocation
  shell: "curl -XPUT 192.168.1.11:9200/_cluster/settings?pretty -H 'Content-Type: application/json' -d '{"persistent" : {\"cluster.routing.allocation.enable" : "primaries"}}'"
                                                                                                          ^ here

1 Ответ

0 голосов
/ 29 февраля 2020

Двойные кавычки внутри других двойных кавычек должны быть исключены.

  shell: "curl -X PUT 192.168.1.11:9200/_cluster/settings?pretty -H 'Content-Type: application/json' -d '{\"persistent\": {\"cluster.routing.allocation.enable\": \"primaries\"}}'"

В таких случаях вы можете упростить свою жизнь и сделать вещи более читабельными, используя сложенный в yaml скалярный блок

  shell: >-
    curl -X PUT 192.168.1.11:9200/_cluster/settings?pretty
    -H 'Content-Type: application/json'
    -d '{"persistent": {"cluster.routing.allocation.enable": "primaries"}}'

Тем временем взгляните на комментарий @Matt Schuchard и рассмотрите возможность использования uri модуля вместо curl в shell.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...