This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
ansible:ansible_cmd [2022/07/26 14:18] manu |
ansible:ansible_cmd [2024/04/19 12:26] (current) manu [All ansible commands] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Ansible command examples ====== | ====== Ansible command examples ====== | ||
| + | |||
| + | ===== All ansible commands ===== | ||
| + | |||
| + | https://docs.ansible.com/ansible/latest/command_guide/command_line_tools.html | ||
| + | |||
| + | **ansible-rulebook** : start a playbook based on a specific event | ||
| + | https://blog.stephane-robert.info/post/ansible-event-driven/ | ||
| + | |||
| + | **ansible-pull** : opposite to ansible is based on the push mode, offering a central management, the pull mode can be use in specific cases | ||
| + | https://blog.octo.com/ansible-pull-killer-feature | ||
| + | | ||
| + | **ansible-galaxy** : get collections of playbooks | ||
| + | |||
| + | **ansible** : Define and run a single task ‘playbook’ against a set of hosts | ||
| + | |||
| + | **ansible-playbook** : Define and run a single task ‘playbook’ against a set of hosts | ||
| + | |||
| + | **ansible-config** : View ansible configuration | ||
| + | |||
| + | **ansible-console** : REPL console for executing Ansible tasks | ||
| + | |||
| + | **ansible-doc** : plugin documentation tool | ||
| + | |||
| + | **ansible-galaxy** : Perform various Role and Collection related operations | ||
| + | |||
| + | **ansible-inventory** : Show Ansible inventory information, by default it uses the inventory script JSON format | ||
| + | |||
| + | **ansible-vault** : encryption/decryption utility for Ansible data files | ||
| + | |||
| + | **ansible-lint** : check playbook syntax | ||
| ===== cmd ===== | ===== cmd ===== | ||
| Line 5: | Line 35: | ||
| <cli prompt='#'> | <cli prompt='#'> | ||
| # ansible all -m ping | # ansible all -m ping | ||
| + | # ansible -vvv -i "node1," all -u user1 -m ping # debug | ||
| # ansible foo.example.com -m yum -a "name=httpd state=installed" | # ansible foo.example.com -m yum -a "name=httpd state=installed" | ||
| # ansible -i hosts all -m yum -a 'name=ncdu state=present' | # ansible -i hosts all -m yum -a 'name=ncdu state=present' | ||
| Line 48: | Line 79: | ||
| aix20 | SUCCESS => {"changed": false,"ping": "pong"} | aix20 | SUCCESS => {"changed": false,"ping": "pong"} | ||
| </cli> | </cli> | ||
| + | |||
| + | <cli prompt='$'> | ||
| + | $ ANSIBLE_REMOTE_USER=user01 ansible all -k -K -m ping | ||
| + | SSH password: | ||
| + | BECOME password[defaults to SSH password]: | ||
| + | 172.16.120.155 | FAILED! => { | ||
| + | "msg": "Using a SSH password instead of a key is not | ||
| + | possible because Host Key checking is enabled and sshpass | ||
| + | does not support this. Please add this host's fingerprint | ||
| + | to your known_hosts file to manage this host." | ||
| + | } | ||
| + | 172.16.120.122 | FAILED! => { | ||
| + | "msg": "Using a SSH password instead of a key is not | ||
| + | possible because Host Key checking is enabled and sshpass | ||
| + | does not support this. Please add this host's fingerprint | ||
| + | to your known_hosts file to manage this host." | ||
| + | } | ||
| + | 172.16.120.123 | SUCCESS => { | ||
| + | "ansible_facts": { | ||
| + | "discovered_interpreter_python": "/usr/libexec/ | ||
| + | platform-python" | ||
| + | }, | ||
| + | "changed": false, | ||
| + | "ping": "pong" | ||
| + | } | ||
| + | </cli> | ||
| + | |||
| + | |||
| File conversion: | File conversion: | ||
| Line 333: | Line 392: | ||
| persistent: yes | persistent: yes | ||
| when: ansible_selinux.status == 'enabled' | when: ansible_selinux.status == 'enabled' | ||
| + | </cli> | ||
| + | |||
| + | ==== change /etc/rc.tcpip ==== | ||
| + | |||
| + | <cli prompt='#'> | ||
| + | # cat update_rc_tcpip.yml | ||
| + | - name: Update /etc/rc.tcpip | ||
| + | gather_facts: no | ||
| + | hosts: ALL | ||
| + | |||
| + | ######################################################################################################### | ||
| + | # Latest version date 06/10/2022 | ||
| + | ######################################################################################################### | ||
| + | # Playbook will comment line "sendmail ..." | ||
| + | ######################################################################################################### | ||
| + | |||
| + | tasks: | ||
| + | |||
| + | - name: Comment line begining with time_last_login | ||
| + | ansible.builtin.lineinfile: | ||
| + | path: /etc/rc.tcpip | ||
| + | regexp: '^start /usr/lib/sendmail' | ||
| + | line: '#start /usr/lib/sendmail "$src_running" "-bd -q${qpi}"' | ||
| + | backup: yes | ||
| + | firstmatch: yes | ||
| + | backrefs: yes | ||
| + | register: results | ||
| + | |||
| + | - name: Restart tcpip demon group if file modified | ||
| + | shell: "/usr/sbin/refresh -g tcpip" | ||
| + | when: results.changed == true | ||
| </cli> | </cli> | ||