This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
ansible:ansible_variables [2021/11/06 19:06] manu |
ansible:ansible_variables [2025/05/21 16:24] (current) manu |
||
|---|---|---|---|
| Line 181: | Line 181: | ||
| opensuse:~ # ansible -i "node2," all -e "var1=toto" -m debug -a 'msg={{ var1 }}' | opensuse:~ # ansible -i "node2," all -e "var1=toto" -m debug -a 'msg={{ var1 }}' | ||
| </cli> | </cli> | ||
| + | |||
| + | ===== Ansible inventory ===== | ||
| + | |||
| + | <cli prompt='$'> | ||
| + | $ ansible --version | grep 'config file' | ||
| + | config file = /home/tux/.ansible.cfg | ||
| + | $ ansible-config dump --only-changed | ||
| + | DEFAULT_BECOME(/home/tux/.ansible.cfg) = True | ||
| + | DEFAULT_BECOME_METHOD(/home/tux/.ansible.cfg) = sudo | ||
| + | DEFAULT_HOST_LIST(/home/tux/.ansible.cfg) = ['/home/tux/ | ||
| + | inventory'] | ||
| + | DEFAULT_REMOTE_USER(/home/tux/.ansible.cfg) = ansible | ||
| + | </cli> | ||
| + | |||
| + | List all hosts, use the keyword **all**. To specify all host not in a group use **ungrouped** | ||
| + | <cli prompt='$'> | ||
| + | $ ansible all --list-hosts | ||
| + | hosts (21): | ||
| + | green.example.com | ||
| + | blue.example.com | ||
| + | 192.168.100.1 | ||
| + | 192.168.100.10 | ||
| + | alpha.example.org | ||
| + | beta.example.org | ||
| + | www001.example.com | ||
| + | www002.example.com | ||
| + | www003.example.com | ||
| + | db-99-node.example.com | ||
| + | db-100-node.example.com | ||
| + | db-101-node.example.com | ||
| + | </cli> | ||
| + | |||
| + | List the group webservers | ||
| + | <cli prompt='$'> | ||
| + | $ ansible webservers --list-hosts | ||
| + | hosts (10): | ||
| + | alpha.example.org | ||
| + | beta.example.org | ||
| + | 192.168.1.100 | ||
| + | 192.168.1.110 | ||
| + | www001.example.com | ||
| + | www002.example.com | ||
| + | www003.example.com | ||
| + | </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> | ||
| + | |||
| + | |||