来自AWS Secret Manager的查找密码| Ansible

时间:2019-04-24 10:11:35

标签: ansible ansible-2.x aws-secrets-manager

使用我在AWS Secrets Manager中创建的Other type of secrets的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代码中?

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

1 个答案:

答案 0 :(得分: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部分中找到