模块的 Ansible 和 route53 不支持参数:连接

Ansible and route53 unsupported parameter for module: connection

我正在尝试 运行 使用 Amazon 的 Route53 服务的 Ansible 剧本,但我在标题中遇到错误。

$ ansible-playbook play-dns.yml
PLAY [localhost] ************************************************************** 
GATHERING FACTS *************************************************************** 
ok: [localhost]
TASK: [configure dns] ********************************************************* 
failed: [localhost] => {"failed": true}
msg: unsupported parameter for module: connection
FATAL: all hosts have already failed -- aborting
PLAY RECAP ******************************************************************** 
          to retry, use: --limit @/home/myuser/play-dns.retry
localhost                  : ok=1    changed=0    unreachable=0    failed=1

这是我的剧本:

$ cat play-dns.yml
---
- hosts: localhost
  tasks:
  - name: configure dns
    route53:
      command: create
      aws_access_key: 'XXXXXXXXXXXXXXXXXXXX'
      aws_secret_key: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
      zone: myzone.info
      record: test.myzone.info
      type: A
      ttl: 7200
      value: 1.1.1.1
      wait: yes
      connection: local

这是我的 Ansible 主机文件:

$ cat /etc/ansible/hosts|grep localhost
[localhost]
localhost           ansible_connection=local

如果我从主机文件中删除 ansible_connection=local

$ cat /etc/ansible/hosts|grep localhost
[localhost]
localhost

然后我得到这个错误:

$ ansible-playbook play-dns.yml
PLAY [localhost] ************************************************************** 
GATHERING FACTS *************************************************************** 
fatal: [localhost] => SSH Error: ssh: connect to host localhost port 22: Connection refused
    while connecting to 127.0.0.1:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.
TASK: [configure dns] ********************************************************* 
fatal: [localhost] => SSH Error: ssh: connect to host localhost port 22: Connection refused
    while connecting to 127.0.0.1:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.
FATAL: all hosts have already failed -- aborting
PLAY RECAP ******************************************************************** 
          to retry, use: --limit @/home/myuser/play-dns.retry
localhost                  : ok=0    changed=0    unreachable=2    failed=0

我做错了什么?

您的问题只是缩进问题。目前 Ansible 正在解析您的剧本并将连接线视为 route53 模块的参数,然后抱怨 connection 不是该模块的有效参数。

相反,您只需要将该行取消缩进到与主机相同的级别,以便 Ansible 将其作为整个剧本而不是模块的参数进行解析:

---
- hosts: localhost
  connection: local
  tasks:
  - name: configure dns
    route53:
      command: create
      aws_access_key: 'XXXXXXXXXXXXXXXXXXXX'
      aws_secret_key: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
      zone: myzone.info
      record: test.myzone.info
      type: A
      ttl: 7200
      value: 1.1.1.1
      wait: yes