Signing back into the Community for the first time? You'll need to reset your password to access your account. Find out more.
Forum Discussion
Former Member
4 years agoonepassword.connect.generic_item task is not being executed when executing playbook with tags
I have a MySQL Ansible role with 2 tags: configure_mysql_users and configure_mysql_databases . Those tags are used for subsequent deployments of databases and users.
Here is a sample playbook f...
Former Member
4 years agoFirst, thank you for providing those detailed reproduction steps! I was able to reproduce this issue locally. I've included the localized version I ran at the end of this post.
I believe this issue is actually with how Ansible handles pre-tasks and tags.
Reproducing the Issue
Here's what I tried and what I saw:
I ran the playbook with the -t "configure_mysql_users,configure_mysql_databases"
flag.
Result =>: setup item
NOT created; item_info
steps failed
I ran playbook without the -t
flag.
Result: setup item
created :+1:
I added tags: ['always']
to the generic_item task in pre_tasks
.
Result => setup_item executed, item_info found the requested fields.
Next Steps
I suggest adding tags: ['always']
to the setup_item task. The generic_item
module is idempotent and won't overwrite the generated fields when you specify generate_value: on_create
for the field.
I found this old post in an Ansible mailing list discussing the issue, but it seems like the behavior still isn't well documented: https://groups.google.com/g/ansible-project/c/VxD39ABi1z4
Let us know if that takes care of the issue!
My local version of your playbook:
```
hosts: localhost
environment:
OP_VAULT: ""
OP_CONNECT_HOST: "http://localhost:8080"
OP_CONNECT_TOKEN: ""
collections:- onepassword.connect pre_tasks:
- name: setup item
onepassword.connect.generic_item:
vault_id: "
" # make sure this is the same as OP_VAULT
in the environment block! title: somehost state: present fields:- label: root_username value: "root" section: "MYSQL (root)"
- label: root_password generate_value: on_create section: "MYSQL (root)" field_type: concealed generator_recipe: length: 16 include_symbols: no
- label: testuser_username value: "testuser" section: "MYSQL (testdb)"
- label: testuser_password generate_value: on_create section: "MYSQL (testdb)" field_type: concealed generator_recipe: length: 16 include_symbols: no
- name: Get root password tags: [ 'always' ] item_info: item: somehost vault: Ansible field: root_password
register: root_password
- name: Get testuser password
tags: [ 'always' ]
item_info:
item: somehost
vault: Ansible
field: testuser_password
register: testuser_password
```