I use Ubuntu 18.04 with Ansible installed this way:

apt-get update -y
install software-properties-common
apt-add-repository ppa:ansible/ansible
apt install ansible

I also have a small Bash script I store in GitHub that I sometimes copy-paste into the terminal of remote machines I hire to store my own websites on (as for now I plan to have only one such remote machine, not tens/hundreds or thousands as common for most Ansible users).

The script

apt-get update -y
apt-get install lamp-server^
apt-get install php-mbstring php-mcrypt php-curl php-cli php-gd
curl -sS https://getcomposer.org/installer -o composer-setup.php
php composer-setup.php --install-dir=/usr/local/bin --filename=composer

One could say "well, if it's just one machine don't use Ansible at all, it would be an overkill" but I still feel the need to automate this as it is a very "messy" installation command set that might change "tomorrow".

My problem

I don't find literature to explain how I could do the same installations, inside the Bash terminal (say from copy-pasting the command set) but with Ansible. I also bought a printed version of Jeff Geerling's book "Ansible for Devops" but none of the basic chapters covers my particular need.

All I find is how to deploy a playbook file to a list of IPs but I don't want to use this "traditional" way for Ansible. I just want to copy a Ansible YAML command set from GitHub to my terminal.

My question

Do you know how I could do that?


Just copy the playbook file to the new host and play it to the local host using the following yaml directives:

  • hosts: The localhost address for nearly any machine.
  • connection: local: A yaml direction for the type of connection; given we work locally in this case, it's conceptually useless, but it's technically necessary due to how the current version of Ansible is built).

See here for the gory details.


From the Ansible Docs:

    - name: Install a list of packages
    name: "{{ packages }}"
    - foo
    - foo-tools

    - name: Download foo.conf
    url: http://example.com/path/file.conf
    dest: /etc/foo.conf
    mode: 0440

Since this is written in Ansible Playbook format. You would need to write it to a yaml file, and then you can call the playbook from your script. You would not be able to embed the yaml file in a bash script and then call it within the script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.