# Cheat Sheet

## Hosts

### Host from variable

Playbook file:

```
- name: Your playbook name
  hosts: "{{ variable_host | default('localhost') }}"
  become: yes
```

To run it:

```bash
ansible-playbook playbooks/your-playbook-name.yml \
  --extra-vars "variable_host=PUT-YOUR-HOST-HERE"
```

## Ping

### Ping all hosts

```bash
ansible all -m ping -u root
```

### Ping localhost

```bash
ansible all -m shell -a "ping -c 3 localhost" -u root
```

## Python virtualenv

Make sure python will load all modules installed in your virtualenv.

```bash
ansible-playbook -v \
  playbooks/my-playbook.yaml \
  --extra-vars="ansible_python_interpreter=$(which python)"
```

## Set RSA key path

```bash
ansible all -m ping -u root --private-key=~/.ssh/id_rsa
```

## Install packages

```bash
ansible all -m apt -a "pkg=nginx state=latest update_cache=true" -u root
```

## Decrypt

### Decrypt string

Make sure your string variable is in group\_vars/all.yml.

```bash
cat group_vars/all.yml
```

For example:

```bash
aws_access_key_id: !vault | $ANSIBLE_VAULT;1.1;AES256 39393635326661316162323939656138666562303765666138333737366139306535303432653537 3036323230616163343135393736343462346464646438320a373234383634646130666333316132 65623561393832666131656365646437643139626532623962646439376364333066323934663661 3031326632385365630a643162643562633231653132393139333737353837633931663764373239 64666537386530366564643336346630666530373664633630323730643261613563
```

Then run:

```bash
ansible YOUR-HOST-HERE -m debug -a 'var=aws_access_key_id'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.devops.buzz/public/ansible/cheat-sheet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
