Skip to content

Instantly share code, notes, and snippets.

@cloudqubes
Created June 7, 2023 03:11
Show Gist options
  • Save cloudqubes/6f6b1936ab05a89b7f6a91998ff03de2 to your computer and use it in GitHub Desktop.
Save cloudqubes/6f6b1936ab05a89b7f6a91998ff03de2 to your computer and use it in GitHub Desktop.

Ansible playbook

- hosts: testvms
  remote_user: ubuntu
  become: yes
  ignore_errors: true

  tasks:
  - name: install nginx
    ansible.builtin.apt:
      name: nginx
      state: latest
      update_cache: yes
    register: nginx #Assigns the return value to 'nginx'
    
  - name: debug nginx installation
    ansible.builtin.debug:
      var: nginx #Print 'nginx' to stdout

Output

$ ansible-playbook -i hosts.yml install-nginx.yml

PLAY [testvms] ************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************
ok: [test_vm]

TASK [install nginx] ******************************************************************************************************************
fatal: [test_vm]: FAILED! => {"changed": false, "msg": "Failed to update apt cache: unknown reason"}
...ignoring

TASK [debug nginx installation] *******************************************************************************************************
ok: [test_vm] => {
    "nginx": {
        "changed": false,
        "failed": true,
        "msg": "Failed to update apt cache: unknown reason"
    }
}

PLAY RECAP ****************************************************************************************************************************
test_vm                 : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment