Ansible tidbit: can I use the environment parameter on a block?

Ansible - environment variable in block

I’ve noticed that when trying to look for Ansible-specific issues or questions, the official documentation usually comes up first, even if it doesn’t answer the question at all. So I’ve decided to write a blog post each time I’ve had to spend time finding an answer to my own question.

To see my other tidbits, just check the Ansible tidbits category.

So… Can I use the environment parameter on an Ansible block?

Answer: Yes. You can totally do this:

tasks:
  - name: Run these tasks with these environment variables
    environment:
      SOME_ENVIRONMENT_VARIABLE: some value

    block:
      - name: some task that uses the env var
        ...

Each task in the block will see and use your environment variables just fine.

There’s not really anything more to say, but really, do you need any more information than this? 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *