Skip to content

Ansible

- name: Check hoge command exists
shell: type hoge
run_once: true
check_mode: false
changed_when: false

https://stackoverflow.com/questions/29399581/using-set-facts-and-with-items-together-in-ansible

- name: Get hoge
set_fact:
colo: "{{ item | unique }}"
with_items: "{{ ansible_play_hosts }}"
register: hoge_result

ansible で nic interface のリストを作成する

Section titled “ansible で nic interface のリストを作成する”
- name: Get physical interfaces names
command: find /sys/class/net -type l -not -lname '*virtual*' -printf '%f\n'
register: physical_interfaces_cmd
changed_when: false
check_mode: false
[ios]
ios1 ansible_host=10.0.1.254
ios2 ansible_host=10.0.2.254
ios3 ansible_host=10.0.3.254
$ ansible-playbook -i inventory.ini ios_show.yml -l '!ios2' --list-hosts
playbook: ios_show.yml
play #1 (ios): ios TAGS: []
pattern: ['ios']
hosts (2):
ios3
ios1