Hi David,
Here is the basic of getting input from the user and reading the file -
```
# ls
1.txt 2.txt main.yml
# cat main.yml
---
- hosts: localhost
gather_facts: no
tasks:
- debug:
msg: "{{ lookup('file', filenumber + '.txt') }}"
# ansible-playbook main.yml -e "filenumber=1"
...
TASK [debug]
*****************************************************************************
ok: [localhost] => {
"msg": "one"
}
...
# ansible-playbook main.yml -e "filenumber=2"
...
TASK [debug]
*****************************************************************************
ok: [localhost] => {
"msg": "two"
}
...
```
You can read more about -
1.
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/debug_module.html
2.
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_lookup.html
3.
https://docs.ansible.com/ansible/latest/reference_appendices/general_precedence.html#using-e-extra-variables-at-the-command-line
On Mon, Jul 17, 2023 at 6:41 AM David Nadelson <[email protected]> wrote:
> Hi All,
> I'm a DBA learning to use ansible to automate. I'm wondering if anyone
> can point me to docs on how to use ansible to select a file based on the
> value of a variable. i.e. if variable=x than choose 1.txt if variable=y
> then choose 2.txt.
>
> Thanks,
>
> David
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/b52e8df2-34bf-4807-b68b-e54cf6386390n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/b52e8df2-34bf-4807-b68b-e54cf6386390n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
Thanks,
Abhijeet Kasurde
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAFwWkHqDbf4CgfQ-GY4q5%3DDaOyz_1uy9z55p%2BtvEbXbt6PFb3A%40mail.gmail.com.