This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
ansible:ansible_variables [2023/08/29 19:57] manu |
ansible:ansible_variables [2025/05/21 16:24] (current) manu |
||
|---|---|---|---|
| Line 182: | Line 182: | ||
| </cli> | </cli> | ||
| - | ==== Ansible inventory ==== | + | ===== Ansible inventory ===== |
| - | <cli prompt='#'> | + | <cli prompt='$'> |
| $ ansible --version | grep 'config file' | $ ansible --version | grep 'config file' | ||
| config file = /home/tux/.ansible.cfg | config file = /home/tux/.ansible.cfg | ||
| Line 195: | Line 195: | ||
| </cli> | </cli> | ||
| - | List all hosts | + | List all hosts, use the keyword **all**. To specify all host not in a group use **ungrouped** |
| - | <cli prompt='#'> | + | <cli prompt='$'> |
| $ ansible all --list-hosts | $ ansible all --list-hosts | ||
| hosts (21): | hosts (21): | ||
| Line 214: | Line 214: | ||
| List the group webservers | List the group webservers | ||
| - | <cli prompt='#'> | + | <cli prompt='$'> |
| $ ansible webservers --list-hosts | $ ansible webservers --list-hosts | ||
| hosts (10): | hosts (10): | ||
| Line 225: | Line 225: | ||
| www003.example.com | www003.example.com | ||
| </cli> | </cli> | ||
| + | |||
| + | Print inventory in YML format | ||
| + | <cli prompt='$'> | ||
| + | $ ansible-inventory --list --yaml | ||
| + | all: | ||
| + | children: | ||
| + | ungrouped: | ||
| + | hosts: | ||
| + | 172.16.120.161: {} | ||
| + | 172.16.120.185: {} | ||
| + | 172.16.120.188: {} | ||
| + | </cli> | ||
| + | |||
| + | ===== Custom variable ===== | ||
| + | |||
| + | ==== Time / date ==== | ||
| + | |||
| + | <code> | ||
| + | - hosts: test | ||
| + | vars: | ||
| + | time: "{{ lookup('pipe', 'date -d \"1 day ago\" +\"%Y%m%d\"') }}" | ||
| + | </code> | ||
| + | |||
| + | |||