Ansible
ansble で 1 回だけ実行する
Section titled “ansble で 1 回だけ実行する”- name: Check hoge command exists shell: type hoge run_once: true check_mode: false changed_when: falseset_fact でリストを作成する
Section titled “set_fact でリストを作成する”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_resultansible で 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ホストを除外する
Section titled “ホストを除外する”[ios]ios1 ansible_host=10.0.1.254ios2 ansible_host=10.0.2.254ios3 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