《OpenShift / RHEL / DevSecOps / Ansible 汇总目录》
在上一篇《Ansible Automation Platform - 用 Ansible Navigator 开发测试 Playbook》一文中,在 Playbook 中使用明文记录了 AAP Controller 的访问地址,以及用户名和密码。我们可以使用以下几种方法对 Playbook 中的敏感进行保护:




$ ansible-navigator exec -- ansible-vault encrypt_string 'my-controller-password' --name 'controller_password'
New Vault password:
Confirm New Vault password:
controller_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
66363232313037626332323035363138623131646334363463626331323862313431386138356365
3836663463353164313631326361353730323734626538640a636262303132336165376461323665
33303062393732646364353333303433643863656331363963633763623838343534333930326333
6235653936306233380a333165376364373963393034386230326430363337396238306164623165
36356163303732646162613638383235626339363530376134343236373730303864
Encryption successful
- hosts: localhost
vars:
controller_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
66363232313037626332323035363138623131646334363463626331323862313431386138356365
3836663463353164313631326361353730323734626538640a636262303132336165376461323665
33303062393732646364353333303433643863656331363963633763623838343534333930326333
6235653936306233380a333165376364373963393034386230326430363337396238306164623165
36356163303732646162613638383235626339363530376134343236373730303864
tasks:
- name: Print password
debug:
msg: 'The controller password is {{ controller_password }}'
$ ansible-navigator run vault-controller-password.yml -m stdout --playbook-artifact-enable false --ask-vault-pass
$ ansible-playbook vault-controller-password.yml --ask-vault-pass
对于一些通用访问目标,例如 VMware、OpenStack 等私有云,AWS、AZure 等公有云、主机操作系统、容器镜像 Registry 等,可以使用 AAP 的凭证记录访问信息。
注意:请参照《Ansible Automation Platform - 在自动化控制台中运行 Playbook》一文了解如何在 AAP 的控制台中通过 “模板” 运行 Playbook、以及如何配置 “凭证”,就不在下文中详细说明每一步的操作步骤了。
---
- name: Create Inventory once piece at a time
hosts: localhost
connection: local
gather_facts: false
collections:
- ansible.controller
tasks:
- name: Add inventory
inventory:
name: Book Inventory
organization: Default
state: present
- name: Add host
host:
name: ansible-client01
inventory: Book Inventory
variables:
hosts_var: 192.168.203.118
state: present
- name: Add group
group:
name: Linux-VM
inventory: Book Inventory
hosts:
- ansible-client01
state: present
