1

使用我Other type of secrets在 AWS Secrets Manager 中创建的 Terraform 代码。我需要在 Ansible 代码中使用这些 AWS 机密。我在下面的链接中找到了这个,但我无法继续。

https://docs.ansible.com/ansible/2.8/plugins/lookup/aws_secret.html

我有以下 Ansible 代码:-

database.yml

- name: Airflow | DB | Create MySQL DB
  mysql_db:
    login_user: "{{ mysql_user }}"
#    login_password: "{{ mysql_root_password }}"
    login_password: "{{ lookup('ca_dev', 'mysql_root_password') }}"
#    config_file: /etc/my.cnf
#    login_unix_socket: /var/lib/mysql/mysql.sock
#    encrypted: yes
    name: "airflow"
    state: "present"

如何将 AWS Secret Manager 合并到我的 ansible 代码中?

在此处输入图像描述

错误信息:-

TASK [../../roles/airflow : Airflow | DB | Create MySQL DB] **************************************************************************************************************************************************************************
task path: /home/ec2-user/cng-ansible/roles/airflow/tasks/database.yml:25
The full traceback is:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 140, in run
    res = self._execute()
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 539, in _execute
    self._task.post_validate(templar=templar)
  File "/usr/lib/python2.7/site-packages/ansible/playbook/task.py", line 267, in post_validate
    super(Task, self).post_validate(templar)
  File "/usr/lib/python2.7/site-packages/ansible/playbook/base.py", line 364, in post_validate
    value = templar.template(getattr(self, name))
  File "/usr/lib/python2.7/site-packages/ansible/template/__init__.py", line 540, in template
    disable_lookups=disable_lookups,
  File "/usr/lib/python2.7/site-packages/ansible/template/__init__.py", line 495, in template
    disable_lookups=disable_lookups,
  File "/usr/lib/python2.7/site-packages/ansible/template/__init__.py", line 746, in do_template
    res = j2_concat(rf)
  File "<template>", line 8, in root
  File "/usr/lib/python2.7/site-packages/jinja2/runtime.py", line 193, in call
    return __obj(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/ansible/template/__init__.py", line 631, in _lookup
    instance = self._lookup_loader.get(name.lower(), loader=self._loader, templar=self)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/loader.py", line 381, in get
    obj = getattr(self._module_cache[path], self.class_name)
AttributeError: 'module' object has no attribute 'LookupModule'

fatal: [127.0.0.1]: FAILED! => {
    "msg": "Unexpected failure during module execution.", 
    "stdout": ""
}

RUNNING HANDLER [../../roles/airflow : restart rabbitmq-server] 
task path: /home/ec2-user/cng-ansible/roles/airflow/handlers/main.yml:28
    to retry, use: --limit @/home/ec2-user/cng-ansible/plays/airflow/installAirflow.retry

PLAY RECAP
127.0.0.1                  : ok=39   changed=7    unreachable=0    failed=1

ansible-doc -t lookup -l输出

在此处输入图像描述

4

1 回答 1

1

该错误{"msg": "lookup plugin (ca_dev) not found"}表明您的问题是该lookup命令的滥用。

以下行:

login_password: "{{ lookup('ca_dev', 'mysql_root_password') }}"

应该看起来像

login_password: "{{ lookup('aws_secret', 'mysql_root_password') }}"

ca_dev不是有效的查找类型,而aws_secretis.

您可以在官方文档的Lookup Plugins部分查看 Ansible 2.8 支持的查找插件列表。

如果您正在使用自定义查找插件,或者将插件从未来版本的 ansible 反向移植到旧版本,则必须确保它位于 ansible 可见的目录中。

您可以将自定义文件放在 ansible 查找的默认位置,也可以~/.ansible/plugins/lookup:/usr/share/ansible/plugins/lookup使用默认部分下的以下 lookup_plugins ini 键将您的 ansible.cfg 配置为在不同的位置查找。

DEFAULT_LOOKUP_PLUGIN_PATH
Description:    Colon separated paths in which Ansible will search for Lookup Plugins.
Type:   pathspec
Default:    ~/.ansible/plugins/lookup:/usr/share/ansible/plugins/lookup
Ini Section:    defaults
Ini Key:    lookup_plugins
Environment:    ANSIBLE_LOOKUP_PLUGINS

这方面的文档可以在官方文档的Ansible 配置部分找到

于 2019-04-25T13:49:21.297 回答