来自AWS秘密经理的查询秘密| Ansible

问题描述 投票:0回答:1

使用Terraform代码我在AWS Secrets Manager中创建了Other type of secrets。我需要在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"

如何在我的ansible代码中加入AWS secret Manager?

enter image description here

错误信息:-

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输出

enter image description here

ansible ansible-2.x aws-secrets-manager
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_secret是。

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

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

您可以将自定义文件放在~/.ansible/plugins/lookup:/usr/share/ansible/plugins/lookup中的默认位置ansible中,也可以使用defaults部分下的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 Configuration部分找到

© www.soinside.com 2019 - 2024. All rights reserved.