Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/konstruktoid/ansible-lastpass-inventory
A dynamic LastPass Ansible Inventory script
https://github.com/konstruktoid/ansible-lastpass-inventory
ansible ansible-inventory hacktoberfest lastpass lastpass-cli
Last synced: about 2 months ago
JSON representation
A dynamic LastPass Ansible Inventory script
- Host: GitHub
- URL: https://github.com/konstruktoid/ansible-lastpass-inventory
- Owner: konstruktoid
- License: apache-2.0
- Created: 2021-10-03T21:31:45.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T06:50:08.000Z (about 2 months ago)
- Last Synced: 2024-10-25T02:05:54.662Z (about 2 months ago)
- Topics: ansible, ansible-inventory, hacktoberfest, lastpass, lastpass-cli
- Language: Python
- Homepage:
- Size: 238 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Dynamic LastPass Ansible Inventory
Requires a [LastPass](https://www.lastpass.com/) account and the [lpass](https://github.com/lastpass/lastpass-cli)
client.The `lastpass_inventory.py` script uses the `lastpass_inventory.yml`
configuration file to fetch the named servers from the current logged in
LastPass account using `lpass`, and then generate an [Ansible](https://www.ansible.com/)
inventory.## Examples and Usage
The `lastpass_inventory.yml` configuration file names and fetches the hosts
using `name: identifier`, where the `name` variable is what the host will be
named in the inventory and the `identifier` is used to identify the host in
LastPass.Both the name and the ID number from e.g. `lpass ls` can be used as an
identifier for a host.If the ID is omitted, the name will be used as the identifier.
Note that the script will fail if the name or ID is incorrect or missing.
The LastPass `user` and `password` fields will be used to populate
`ansible_user`, `ansible_password` and `ansible_become_password`.
The `ansible_host` address is the extracted netloc from the LastPass `url` field
using [urllib.parse.urlparse](https://docs.python.org/3/library/urllib.parse.html).Example `lpass ls` output:
```console
servers
ansible-managed
test-server-01 [id: 3024014487647346952]
test-server-02 [id: 7815456364361241116]
```Configuration file based on the above output:
```yaml
---
lastpass_hosts:
test-server-01:
test-server-02: test-server-02
webserver: test-server-01
database: "7815456364361241116"
...
```Running `ansible-inventory -i lastpass_inventory.py --list --yaml` will then
generate the following inventory:```yaml
all:
children:
lastpass_hosts:
hosts:
database:
ansible_become_password: SuperSecretLastPass
ansible_host: 10.0.1.2
ansible_password: SuperSecretLastPass
ansible_user: ansibleuser
test-server-01:
ansible_host: 10.0.1.1
ansible_user: ansibleuser
test-server-02:
ansible_become_password: SuperSecretLastPass
ansible_host: 10.0.1.2
ansible_password: SuperSecretLastPass
ansible_user: ansibleuser
webserver:
ansible_host: 10.0.1.1
ansible_user: ansibleuser
ungrouped: {}
```