Difference between revisions of "ansible notes"
From thelinuxwiki
(→loops) |
|||
(8 intermediate revisions by one user not shown) | |||
Line 10: | Line 10: | ||
===[https://docs.ansible.com/ansible/latest/vault_guide/vault.html#vault Ansible Vault]=== | ===[https://docs.ansible.com/ansible/latest/vault_guide/vault.html#vault Ansible Vault]=== | ||
Find out how to encrypt sensitive content in your inventory such as passwords and keys. | Find out how to encrypt sensitive content in your inventory such as passwords and keys. | ||
− | |||
variable ansible_connection | variable ansible_connection | ||
Line 26: | Line 25: | ||
docker Run tasks in docker containers | docker Run tasks in docker containers | ||
... | ... | ||
+ | |||
+ | ==playbooks== | ||
+ | ===examples=== | ||
+ | - name: My first play | ||
+ | hosts: myhosts | ||
+ | tasks: | ||
+ | - name: Print wall message | ||
+ | ansible.builtin.command: /usr/bin/wall hello | ||
+ | |||
+ | |||
+ | - name: output test | ||
+ | hosts: myhosts | ||
+ | tasks: | ||
+ | - name: run uname thru awk | ||
+ | ansible.builtin.shell: /usr/bin/uname -a | awk '{print $NF}' | ||
+ | register: results | ||
+ | - debug: | ||
+ | var: results.stdout | ||
+ | |||
+ | $ '''ansible-playbook -i inventory.ini shelltest.yaml''' | ||
+ | PLAY [output test] ******************************************************************************************************************************** | ||
+ | <br> | ||
+ | TASK [run uname thru awk] ************************************************************************************************************************* | ||
+ | changed: [10.0.0.15] | ||
+ | <br> | ||
+ | TASK [debug] ************************************************************************************************************************************** | ||
+ | ok: [10.0.0.15] => { | ||
+ | "results.stdout": "GNU/Linux" | ||
+ | } | ||
+ | <br> | ||
+ | PLAY RECAP **************************************************************************************************************************************** | ||
+ | 10.0.0.15 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 | ||
+ | |||
+ | ==network automation== | ||
+ | ===platform modules=== | ||
+ | [https://docs.ansible.com/ansible/latest/network/user_guide/platform_index.html#platform-options platform modules (Maintained by Ansible Network Team)] | ||
+ | |||
+ | [https://galaxy.ansible.com/ui/namespaces/check_point/ checkpoint modules (gaia / mgmt)] | ||
+ | |||
+ | [https://galaxy.ansible.com/ui/namespaces/fortinet/ fortinet] | ||
+ | |||
+ | [https://galaxy.ansible.com/ui/namespaces/paloaltonetworks/ paloalto] | ||
+ | |||
+ | ==programming== | ||
+ | |||
+ | ===[https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_conditionals.html conditionals]=== | ||
+ | |||
+ | ===[https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html loops]=== | ||
+ | |||
+ | ==output== | ||
+ | ===parsing json=== | ||
+ | [https://docs.ansible.com/ansible/latest/collections/community/general/docsite/filter_guide_selecting_json_data.html Selecting JSON data: JSON queries] | ||
[[category:ansible]] | [[category:ansible]] |
Revision as of 04:05, 19 April 2024
Contents |
installation
pip install ansible
Adding variables to inventory
Connecting to hosts
Ansible Vault
Find out how to encrypt sensitive content in your inventory such as passwords and keys.
variable ansible_connection
listing connection types/plugins
$ ansible-doc -t connection -l kubectl Execute tasks in pods running on Kubernetes libvirt_lxc Run tasks in lxc containers via libvirt chroot Interact with local chroot psrp Run tasks over Microsoft PowerShell Remoting Protocol network_cli Use network_cli to run command on network appliances vmware_tools Execute tasks inside a VM via VMware Tools ssh connect via ssh client binary httpapi Use httpapi to run command on network appliances docker Run tasks in docker containers ...
playbooks
examples
- name: My first play hosts: myhosts tasks: - name: Print wall message ansible.builtin.command: /usr/bin/wall hello
- name: output test hosts: myhosts tasks: - name: run uname thru awk ansible.builtin.shell: /usr/bin/uname -a | awk '{print $NF}' register: results - debug: var: results.stdout
$ ansible-playbook -i inventory.ini shelltest.yaml PLAY [output test] ********************************************************************************************************************************
TASK [run uname thru awk] ************************************************************************************************************************* changed: [10.0.0.15]
TASK [debug] ************************************************************************************************************************************** ok: [10.0.0.15] => { "results.stdout": "GNU/Linux" }
PLAY RECAP **************************************************************************************************************************************** 10.0.0.15 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
network automation
platform modules
platform modules (Maintained by Ansible Network Team)
checkpoint modules (gaia / mgmt)