Template: src=2 dest=/usr/share/nginx/html/index.html Modify the my_playbook_2.yaml accordingly and save it to my_playbook_3.yaml:Īpt: pkg=nginx state=installed update_cache=true Here is the result for the production server:Īs a sample for potential database updates, we'll add another variable on the 2: Let's check what files we have in our lsĮsktop hosts 2 to play with our playbook ( ansible-playbook -i hosts -s -u ubuntu my_playbook_2.yaml We used the "raw" module to run a command. The "gather_facts: False" on the playbook allows implicit fact gathering to be skipped. Raw: test -e /usr/bin/python || (apt -y update & apt install -y python-minimal)Īctually, because the tasks in the playbook are more like bootstraping of the instances we may name it as "pre_tasks". Where the playbook ( my_playbook.yaml) looks like this ( ref): $ ansible-playbook -i hosts -s -u ubuntu my_playbook.yaml "ping": newer instances such as ubuntu 16, we need to run tasks in playbook: We can check only the production server which is specified as "prod" in our inventory file, ansible -i hosts prod -m ping -u ubuntu "-u" specifies the user, and in our case, it's ubuntu.The "-i" is for inventory, and we want to test all.We run a simple Ansible testing command, and the json output looks good. Let's do a simple connection testing (this used to be working with aws ubuntu ls Once our local machine's public key record is in the "authorized_keys" of remote node, we can ssh to the AWS instance (52.54.142.56) from our local ssh create another instance (18.209.15.95) do the same things.Ĭonnection test with Ansible basic command Now we'll be able to add our public key to the authorized_keys file on remote ssh-copy-id -f of key(s) added: 1 Identity added: /home/ansible/.ssh/einsteinish.pem ssh-add -lĢ048 SHA256:NQp2twy8c9Leaht4Z0r7Whgpr97wIhLJB6kFIQfU3j0 /home/ansible/.ssh/einsteinish.pem (RSA) Probably, we may need to add ec2 key-pair (*.pem) into the ssh-add ~/.ssh/einsteinish.pem But before we doing it, "ssh-agent" should be running on our control (most likely local eval `ssh-agent -s` Ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsivZ9l1v/gF2O2QzNthm1B9ugt9WVBSBEn0Rrz圆ksSjPT/I64a8aADjsDG61SNapidzd86HBd2WubIiVAJvQLr3h0pN6n36Eba7D3Z/krmRmRRxjcXFvabnedCTGpzNsRH0ByvNtzQfyp7bo7Ul1N5Sup7aAmt2HlOvzdx1zxwxNm4eohS6e3VpaGmmLBTJ1ZcyHgSnMbM+nsD6KTAykJPAwt0Xze6amrfNvaIElxZFZEb6mEE0SjcRKZeMaGfnwTQMQgXz3YDl4Ngso10TPhrN0sSa10DMi9mlTV7ruQxUMmxaZMZq3rzAKvcNC7NWkIZYmaFQ2SXBJ4BcsJUQV place the public key at our remote host, instead of logging into that machine, we can use ssh-copy-id. However, here we'll put our public key ( /home/ans/.ssh/id_rsa.pub) for "ans" user into the /home/ubuntu/.ssh/authorized_keys file : we create an EC2 instance, AWS provides us a key and we can use it to access the instance. Your identification has been saved in /home/ans/.ssh/id_rsa. So, let's create ssh-keygenĮnter file in which to save the key (/home/ans/.ssh/id_rsa):Įnter passphrase (empty for no passphrase): Is the information correct? su ssh to our remote servers, we need ssh key. Įnter the new value, or press ENTER for the default On local machine, we may want to create a user sudo adduser -home /home/ans -shell /bin/bash ansĪdding new user `ans' (1006) with group `ans'.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |