r/ansible

Image 1 — Ansible-lint going crazy?
Image 2 — Ansible-lint going crazy?
▲ 19 r/ansible

Ansible-lint going crazy?

Hi all,

Been finalizing a playbook and al of the sudden I see that Ansible-lint (using VS Code) mentions that the 3 dashes to start the .yaml file has a syntax error!?!?

Also a screenshot of the syntax error message.

I've check my playbook with yaml checkers online and all is showing ok, no errors. So why is VS Code (yes, I have selected the Ansible language in VS Code) showing this yellow line, syntax error?

My whole playbook is free of errors. All indentations and stuff is correct, checked over and over..

Anybody an idea?

TIA

[UPDATE]

Found the issue, though not solved yet:

  vars_files:
    - Ansible_Secret/Ans_Cred.yaml

# also tried the following:
# ==============================
    - ./Ansible_Secret/Ans_Cred.yaml

    - ../Ansible_Secret/Ans_Cred.yaml

    - "{{ playbook_dir }}/Ansible_Secret/Ans_Cred.yaml"

# Neither this solved it, include_vars can only be used in the "tasks"-section.
  pre_tasks:
    - name: Include all vars files.
      ansible.builtin.include_vars:
        file: "{{ playbook_dir }}/Ansible_Secret/Ans_Cred.yaml"

The file Ans_Cred.yaml is in a separate directory because I don't want to sync secrets into the cloud. This folder is in the root of the directory where I also have the playbook. Like it is mentioned in the examples in the code block above, it keeps showing the 3 dashes yellow underlined as syntax-error.

The only way the syntax-error disappears is by doing:

  vars_files:
    - /Ansible_Secret/Ans_Cred.yaml

But then the playbook errors because it cannot find the variables (the credentials file)...which is obvious because here I'm pointing it to be in the root of my drive where the file not exists.

Any suggestions on this?

u/Patrice_77 — 11 days ago

Need help deploying a PKI

Hello everyone, hope you're having a nice day !

As the title says I'm making this post to asks some help about the deployment of a kind of PKI.

I am currently learning Ansible and going through some basics steps. I've got 3 VMs with my provider openstack. 2 have a role 'monitored' and the other has the role 'tracker'. The inventory is managed dynamically and I have already written down tasks for each of them (tracker installs prometheus and monitored installs node_exporter).

In my playbook, these roles runs before the role pki that will generate, deploy and update configurations files based on the certificates it will have generated.

I'm stuck at securing the communication between prometheus and each node_exporter.

I made another role called 'pki' that is doing the following tasks :
- Generates a rootCA private key
- Generates a rootCA CSR
- Generates a rootCA certificate
- Generates for each host private keys and CSRs
- Sign hosts CSRs with rootCA
- Deploy the rootCA certificate and all VMs and transfer their private key and certificate
- Update node_exporter VMs configuration to use the certificates and private key
- Update prometheus configuration to scrape over HTTPS

In my opinion I think I'm doing too much for nothing, there must be a simpler way but I can't figure it out. I've tried to use the help of LLMs but as I'm still new to ansible world I'm not copy pasting something I don't fully understand.

Thanks a lot for any advice you can give me !

Wishing you a great day :)

reddit.com
u/Lucky-Pollution-2506 — 10 days ago