Ansible Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Ansible =Execute a Shell Command on all Hosts in Some Groups= <pre> ansible masters,nodes -m shell -a"systemctl status docker | grep Activ...")
 
 
(10 intermediate revisions by the same user not shown)
Line 2: Line 2:


* [[Ansible#Subjects|Ansible]]
* [[Ansible#Subjects|Ansible]]
=Command Line Options=
==-b==
"Become" another user when running the command.
==--become-user=<''username''>==
==-m==
Defines the module to run.
==-a==
Pass arguments to the module.
=Ping all Hosts from a Group=
This will also list the hosts from that group.
<Pre>
ansible all -m ping
</pre>


=Execute a Shell Command on all Hosts in Some Groups=
=Execute a Shell Command on all Hosts in Some Groups=


<pre>
<pre>
ansible masters,nodes -m shell -a"systemctl status docker | grep Active"
ansible masters,nodes -m shell -a "systemctl status docker | grep Active"
</pre>
</pre>
=Copy Files=
<pre>
ansible <my-servers> -m copy -a "src=/root/ipa-ca.crt dest=/etc/origin/master"
</pre>
=ansible-playbook=
{{Internal|ansible-playbook|ansible-playbook}}
=Provide In-Line Prompt Confirmation=
ansible-playbook ... -e reset_confirmation=yes
where "reset_confirmation" is defined in playbook:
- hosts: etcd:k8s-cluster:calico-rr
  pre_tasks:
    - name: check confirmation
      fail:
        msg: "Reset confirmation failed"
      when: reset_confirmation != "yes"
=SSH Configuration=
... --ask-pass --ssh-extra-args='-o "PubkeyAuthentication=no"' ...
==SSH Host Key Authenticity Checking==
{{Internal|Ansible_Configuration#SSH_Host_Key_Authenticity_Checking|ansible.cfg}}
=Troubleshooting=
{{External|https://docs.ansible.com/ansible/latest/user_guide/playbooks_debugger.html}}
Run ansible-playbook with -vvvvv

Latest revision as of 05:47, 19 January 2021

Internal

Command Line Options

-b

"Become" another user when running the command.

--become-user=<username>

-m

Defines the module to run.

-a

Pass arguments to the module.

Ping all Hosts from a Group

This will also list the hosts from that group.

ansible all -m ping

Execute a Shell Command on all Hosts in Some Groups

ansible masters,nodes -m shell -a "systemctl status docker | grep Active"

Copy Files

ansible <my-servers> -m copy -a "src=/root/ipa-ca.crt dest=/etc/origin/master"

ansible-playbook

ansible-playbook

Provide In-Line Prompt Confirmation

ansible-playbook ... -e reset_confirmation=yes

where "reset_confirmation" is defined in playbook:

- hosts: etcd:k8s-cluster:calico-rr

  pre_tasks:
    - name: check confirmation
      fail:
        msg: "Reset confirmation failed"
      when: reset_confirmation != "yes"

SSH Configuration

... --ask-pass --ssh-extra-args='-o "PubkeyAuthentication=no"' ...

SSH Host Key Authenticity Checking

ansible.cfg

Troubleshooting

https://docs.ansible.com/ansible/latest/user_guide/playbooks_debugger.html

Run ansible-playbook with -vvvvv