Spinning EC2 instance using Ansible

[root@ip-172-31-46-185 ~]# /usr/local/bin/pip install boto
Requirement already satisfied: boto in /usr/lib/python2.7/dist-packages
[root@ip-172-31-46-185 ~]# /usr/local/bin/pip install ansible
Collecting ansible
  Downloading ansible-2.3.2.0.tar.gz (4.3MB)
    100% |████████████████████████████████| 4.3MB 272kB/s
Requirement already satisfied: jinja2 in /usr/lib/python2.7/dist-packages (from ansible)
Requirement already satisfied: PyYAML in /usr/lib64/python2.7/dist-packages (from ansible)
Requirement already satisfied: paramiko in /usr/lib/python2.7/dist-packages (from ansible)
Requirement already satisfied: pycrypto>=2.6 in /usr/lib64/python2.7/dist-packages (from ansible)
Requirement already satisfied: setuptools in /usr/lib/python2.7/dist-packages (from ansible)
Requirement already satisfied: markupsafe in /usr/lib64/python2.7/dist-packages (from jinja2->ansible)
Requirement already satisfied: ecdsa>=0.11 in /usr/lib/python2.7/dist-packages (from paramiko->ansible)
Installing collected packages: ansible
  Running setup.py install for ansible ... done
Successfully installed ansible-2.3.2.0
[root@ip-172-31-46-185 ~]# ansible
Usage: ansible [options]

Options:
  -a MODULE_ARGS, --args=MODULE_ARGS
                        module arguments
  --ask-vault-pass      ask for vault password
  -B SECONDS, --background=SECONDS
                        run asynchronously, failing after X seconds
                        (default=N/A)
  -C, --check           don't make any changes; instead, try to predict some
                        of the changes that may occur
  -D, --diff            when changing (small) files and templates, show the
                        differences in those files; works great with --check
  -e EXTRA_VARS, --extra-vars=EXTRA_VARS
                        set additional variables as key=value or YAML/JSON
  -f FORKS, --forks=FORKS
                        specify number of parallel processes to use
                        (default=5)
  -h, --help            show this help message and exit
  -i INVENTORY, --inventory-file=INVENTORY
                        specify inventory host path
                        (default=/etc/ansible/hosts) or comma separated host
                        list.
  -l SUBSET, --limit=SUBSET
                        further limit selected hosts to an additional pattern
  --list-hosts          outputs a list of matching hosts; does not execute
                        anything else
  -m MODULE_NAME, --module-name=MODULE_NAME
                        module name to execute (default=command)
  -M MODULE_PATH, --module-path=MODULE_PATH
                        specify path(s) to module library (default=None)
  --new-vault-password-file=NEW_VAULT_PASSWORD_FILE
                        new vault password file for rekey
  -o, --one-line        condense output
  --output=OUTPUT_FILE  output file name for encrypt or decrypt; use - for
                        stdout
  -P POLL_INTERVAL, --poll=POLL_INTERVAL
                        set the poll interval if using -B (default=15)
  --syntax-check        perform a syntax check on the playbook, but do not
                        execute it
  -t TREE, --tree=TREE  log output to this directory
  --vault-password-file=VAULT_PASSWORD_FILE
                        vault password file
  -v, --verbose         verbose mode (-vvv for more, -vvvv to enable
                        connection debugging)
  --version             show program's version number and exit

  Connection Options:
    control as whom and how to connect to hosts

    -k, --ask-pass      ask for connection password
    --private-key=PRIVATE_KEY_FILE, --key-file=PRIVATE_KEY_FILE
                        use this file to authenticate the connection
    -u REMOTE_USER, --user=REMOTE_USER
                        connect as this user (default=None)
    -c CONNECTION, --connection=CONNECTION
                        connection type to use (default=smart)
    -T TIMEOUT, --timeout=TIMEOUT
                        override the connection timeout in seconds
                        (default=10)
    --ssh-common-args=SSH_COMMON_ARGS
                        specify common arguments to pass to sftp/scp/ssh (e.g.
                        ProxyCommand)
    --sftp-extra-args=SFTP_EXTRA_ARGS
                        specify extra arguments to pass to sftp only (e.g. -f,
                        -l)
    --scp-extra-args=SCP_EXTRA_ARGS
                        specify extra arguments to pass to scp only (e.g. -l)
    --ssh-extra-args=SSH_EXTRA_ARGS
                        specify extra arguments to pass to ssh only (e.g. -R)

  Privilege Escalation Options:
    control how and which user you become as on target hosts

    -s, --sudo          run operations with sudo (nopasswd) (deprecated, use
                        become)
    -U SUDO_USER, --sudo-user=SUDO_USER
                        desired sudo user (default=root) (deprecated, use
                        become)
    -S, --su            run operations with su (deprecated, use become)
    -R SU_USER, --su-user=SU_USER
                        run operations with su as this user (default=root)
                        (deprecated, use become)
    -b, --become        run operations with become (does not imply password
                        prompting)
    --become-method=BECOME_METHOD
                        privilege escalation method to use (default=sudo),
                        valid choices: [ sudo | su | pbrun | pfexec | doas |
                        dzdo | ksu | runas ]
    --become-user=BECOME_USER
                        run operations as this user (default=root)
    --ask-sudo-pass     ask for sudo password (deprecated, use become)
    --ask-su-pass       ask for su password (deprecated, use become)
    -K, --ask-become-pass
                        ask for privilege escalation password
ERROR! Missing target hosts
[root@ip-172-31-46-185 ~]# pwd
/root
[root@ip-172-31-46-185 ~]# vi aws-secrets
[root@ip-172-31-46-185 ~]#
[root@ip-172-31-46-185 ~]#
[root@ip-172-31-46-185 ~]# cat aws-secrets
Access Key ID:
AKIAJYOQNYVOVBQIBFQQ
Secret Access Key:
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
[root@ip-172-31-46-185 ~]#
[root@ip-172-31-46-185 ~]#
[root@ip-172-31-46-185 ~]#
[root@ip-172-31-46-185 ~]# export AWS_ACCESS_KEY_ID="AKIAJYOQNYVOVBQIBFQQ"
[root@ip-172-31-46-185 ~]# export AWS_SECRET_ACCESS_KEY="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"
[root@ip-172-31-46-185 ~]# vi hosts
[root@ip-172-31-46-185 ~]#
[root@ip-172-31-46-185 ~]#
[root@ip-172-31-46-185 ~]# vi ec2-basic.yml
[root@ip-172-31-46-185 ~]#
[root@ip-172-31-46-185 ~]# ll
total 12
-rw-r--r-- 1 root root   96 Sep  4 19:08 aws-secrets
-rw-r--r-- 1 root root 2458 Sep  4 19:30 ec2-basic.yml
-rw-r--r-- 1 root root   31 Sep  4 19:10 hosts
[root@ip-172-31-46-185 ~]# ansible-playbook -i ./hosts ec2-basic.yml

PLAY [Provision an EC2 Instance] ****************************************************************************

TASK [Create a security group] ******************************************************************************
fatal: [localhost -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Region us-east-1c does                                                            not seem to be available for aws module boto.ec2. If the region definitely exists, you may need to upgrade b                                                           oto or extend with endpoints_path"}
        to retry, use: --limit @/root/ec2-basic.retry

PLAY RECAP **************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1

[root@ip-172-31-46-185 ~]# vi ec2-basic.yml
[root@ip-172-31-46-185 ~]# ansible-playbook -i ./hosts ec2-basic.yml

PLAY [Provision an EC2 Instance] ****************************************************************************

TASK [Create a security group] ******************************************************************************
fatal: [localhost -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Region us-east-1b does                                                            not seem to be available for aws module boto.ec2. If the region definitely exists, you may need to upgrade b                                                           oto or extend with endpoints_path"}
        to retry, use: --limit @/root/ec2-basic.retry

PLAY RECAP **************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1

[root@ip-172-31-46-185 ~]# vi ec2-basic.yml

[root@ip-172-31-46-185 ~]# cat ec2-basic.yml
---
  - name: Provision an EC2 Instance
    hosts: local
    connection: local
    gather_facts: False
    tags: provisioning
    # Necessary Variables for creating/provisioning the EC2 Instance
    vars:
      instance_type: t2.micro
      security_group: web-Security-Group-1 # Change the security group name here
      image: ami-a4c7edb2 # This is an AMI i created myself
      keypair:  newkeyaug2017 # This is one of my keys that i already have in AWS
      region: us-east-1 # Change the Region
      count: 2

    # Task that will be used to Launch/Create an EC2 Instance
    tasks:

      - name: Create a security group
        local_action:
          module: ec2_group
          name: "{{ security_group }}"
          description: Security Group for webserver Servers
          region: "{{ region }}"
          rules:
            - proto: tcp
              from_port: 22
              to_port: 22
              cidr_ip: 0.0.0.0/0
            - proto: tcp
              from_port: 80
              to_port: 80
              cidr_ip: 0.0.0.0/0
            - proto: tcp
              from_port: 443
              to_port: 443
              cidr_ip: 0.0.0.0/0
          rules_egress:
            - proto: all
              cidr_ip: 0.0.0.0/0
        register: basic_firewall

      - name: Launch the new EC2 Instance
        local_action: ec2
                      group={{ security_group }}
                      instance_type={{ instance_type}}
                      image={{ image }}
                      wait=true
                      region={{ region }}
                      keypair={{ keypair }}
                      count={{count}}
        register: ec2

      - name: Wait for SSH to come up
        local_action: wait_for
                      host={{ item.public_ip }}
                      port=22
                      state=started
        with_items: ec2.instances

      - name: Add tag to Instance(s)
        local_action: ec2_tag resource={{ item.id }} region={{ region }} state=present
        with_items: ec2.instances
        args:
          tags:
            Name: webserver
[root@ip-172-31-46-185 ~]#


[root@ip-172-31-46-185 ~]# python
Python 2.7.12 (default, Sep  1 2016, 22:14:00)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto.ec2
>>> boto.ec2.regions()
[RegionInfo:us-east-1, RegionInfo:us-west-1, RegionInfo:cn-north-1, RegionInfo:ap-northeast-1, RegionInfo:ap-                                                           southeast-2, RegionInfo:sa-east-1, RegionInfo:ap-southeast-1, RegionInfo:ap-northeast-2, RegionInfo:us-west-2                                                           , RegionInfo:us-gov-west-1, RegionInfo:ap-south-1, RegionInfo:eu-central-1, RegionInfo:eu-west-1]
>>> pip upgrade boto
  File "", line 1
    pip upgrade boto
              ^
SyntaxError: invalid syntax
>>> upgrade boto
  File "", line 1
    upgrade boto
               ^
SyntaxError: invalid syntax
>>>
[root@ip-172-31-46-185 ~]# /usr/local/bin/pip install boto-2.4.5
Collecting boto-2.4.5
  Could not find a version that satisfies the requirement boto-2.4.5 (from versions: )
No matching distribution found for boto-2.4.5
[root@ip-172-31-46-185 ~]# /usr/local/bin/pip install boto*
Invalid requirement: 'boto*'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 82, in __init__
    req = Requirement(req)
  File "/usr/local/lib/python2.7/site-packages/pip/_vendor/packaging/requirements.py", line 96, in __init__
    requirement_string[e.loc:e.loc + 8]))
InvalidRequirement: Invalid requirement, parse error at "'*'"

[root@ip-172-31-46-185 ~]# /usr/local/bin/pip list boto
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (                                                           or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
ansible (2.3.2.0)
aws-cfn-bootstrap (1.4)
awscli (1.11.132)
Babel (0.9.4)
backports.ssl-match-hostname (3.4.0.2)
boto (2.42.0)
botocore (1.5.95)
chardet (2.0.1)
cloud-init (0.7.6)
colorama (0.2.5)
configobj (4.7.2)
docutils (0.11)
ecdsa (0.11)
futures (3.0.3)
iniparse (0.3.1)
Jinja2 (2.7.2)
jmespath (0.9.2)
jsonpatch (1.2)
jsonpointer (1.0)
kitchen (1.1.1)
lockfile (0.8)
MarkupSafe (0.11)
paramiko (1.15.1)
PIL (1.1.6)
pip (9.0.1)
ply (3.4)
pyasn1 (0.1.7)
pycrypto (2.6.1)
pycurl (7.19.0)
pygpgme (0.3)
pyliblzma (0.5.3)
pystache (0.5.3)
python-daemon (1.5.2)
python-dateutil (2.1)
pyxattr (0.5.0)
PyYAML (3.10)
requests (1.2.3)
rsa (3.4.1)
setuptools (12.2)
simplejson (3.6.5)
six (1.8.0)
urlgrabber (3.10)
urllib3 (1.8.2)
virtualenv (12.0.7)
yum-metadata-parser (1.1.4)
[root@ip-172-31-46-185 ~]# /usr/local/bin/pip list |grep boto
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (                                                           or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
boto (2.42.0)
botocore (1.5.95)
[root@ip-172-31-46-185 ~]# python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/lib64/python2.7/site.pyc matches /usr/lib64/python2.7/site.py
import site # precompiled from /usr/lib64/python2.7/site.pyc
# /usr/lib64/python2.7/os.pyc matches /usr/lib64/python2.7/os.py
import os # precompiled from /usr/lib64/python2.7/os.pyc
import errno # builtin
import posix # builtin
# /usr/lib64/python2.7/posixpath.pyc matches /usr/lib64/python2.7/posixpath.py
import posixpath # precompiled from /usr/lib64/python2.7/posixpath.pyc
# /usr/lib64/python2.7/stat.pyc matches /usr/lib64/python2.7/stat.py
import stat # precompiled from /usr/lib64/python2.7/stat.pyc
# /usr/lib64/python2.7/genericpath.pyc matches /usr/lib64/python2.7/genericpath.py
import genericpath # precompiled from /usr/lib64/python2.7/genericpath.pyc
# /usr/lib64/python2.7/warnings.pyc matches /usr/lib64/python2.7/warnings.py
import warnings # precompiled from /usr/lib64/python2.7/warnings.pyc
# /usr/lib64/python2.7/linecache.pyc matches /usr/lib64/python2.7/linecache.py
import linecache # precompiled from /usr/lib64/python2.7/linecache.pyc
# /usr/lib64/python2.7/types.pyc matches /usr/lib64/python2.7/types.py
import types # precompiled from /usr/lib64/python2.7/types.pyc
# /usr/lib64/python2.7/UserDict.pyc matches /usr/lib64/python2.7/UserDict.py
import UserDict # precompiled from /usr/lib64/python2.7/UserDict.pyc
# /usr/lib64/python2.7/_abcoll.pyc matches /usr/lib64/python2.7/_abcoll.py
import _abcoll # precompiled from /usr/lib64/python2.7/_abcoll.pyc
# /usr/lib64/python2.7/abc.pyc matches /usr/lib64/python2.7/abc.py
import abc # precompiled from /usr/lib64/python2.7/abc.pyc
# /usr/lib64/python2.7/_weakrefset.pyc matches /usr/lib64/python2.7/_weakrefset.py
import _weakrefset # precompiled from /usr/lib64/python2.7/_weakrefset.pyc
import _weakref # builtin
# /usr/lib64/python2.7/copy_reg.pyc matches /usr/lib64/python2.7/copy_reg.py
import copy_reg # precompiled from /usr/lib64/python2.7/copy_reg.pyc
# /usr/lib64/python2.7/traceback.pyc matches /usr/lib64/python2.7/traceback.py
import traceback # precompiled from /usr/lib64/python2.7/traceback.pyc
# /usr/lib64/python2.7/sysconfig.pyc matches /usr/lib64/python2.7/sysconfig.py
import sysconfig # precompiled from /usr/lib64/python2.7/sysconfig.pyc
# /usr/lib64/python2.7/re.pyc matches /usr/lib64/python2.7/re.py
import re # precompiled from /usr/lib64/python2.7/re.pyc
# /usr/lib64/python2.7/sre_compile.pyc matches /usr/lib64/python2.7/sre_compile.py
import sre_compile # precompiled from /usr/lib64/python2.7/sre_compile.pyc
import _sre # builtin
# /usr/lib64/python2.7/sre_parse.pyc matches /usr/lib64/python2.7/sre_parse.py
import sre_parse # precompiled from /usr/lib64/python2.7/sre_parse.pyc
# /usr/lib64/python2.7/sre_constants.pyc matches /usr/lib64/python2.7/sre_constants.py
import sre_constants # precompiled from /usr/lib64/python2.7/sre_constants.pyc
dlopen("/usr/lib64/python2.7/lib-dynload/_localemodule.so", 2);
import _locale # dynamically loaded from /usr/lib64/python2.7/lib-dynload/_localemodule.so
# /usr/lib64/python2.7/_sysconfigdata.pyc matches /usr/lib64/python2.7/_sysconfigdata.py
import _sysconfigdata # precompiled from /usr/lib64/python2.7/_sysconfigdata.pyc
import encodings # directory /usr/lib64/python2.7/encodings
# /usr/lib64/python2.7/encodings/__init__.pyc matches /usr/lib64/python2.7/encodings/__init__.py
import encodings # precompiled from /usr/lib64/python2.7/encodings/__init__.pyc
# /usr/lib64/python2.7/codecs.pyc matches /usr/lib64/python2.7/codecs.py
import codecs # precompiled from /usr/lib64/python2.7/codecs.pyc
import _codecs # builtin
# /usr/lib64/python2.7/encodings/aliases.pyc matches /usr/lib64/python2.7/encodings/aliases.py
import encodings.aliases # precompiled from /usr/lib64/python2.7/encodings/aliases.pyc
# /usr/lib64/python2.7/encodings/utf_8.pyc matches /usr/lib64/python2.7/encodings/utf_8.py
import encodings.utf_8 # precompiled from /usr/lib64/python2.7/encodings/utf_8.pyc
Python 2.7.12 (default, Sep  1 2016, 22:14:00)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/usr/lib64/python2.7/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /usr/lib64/python2.7/lib-dynload/readline.so
>>>
# clear __builtin__._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.exitfunc
# clear sys.exc_type
# clear sys.exc_value
# clear sys.exc_traceback
# clear sys.last_type
# clear sys.last_value
# clear sys.last_traceback
# clear sys.path_hooks
# clear sys.path_importer_cache
# clear sys.meta_path
# clear sys.flags
# clear sys.float_info
# restore sys.stdin
# restore sys.stdout
# restore sys.stderr
# cleanup __main__
# cleanup[1] encodings
# cleanup[1] site
# cleanup[1] sysconfig
# cleanup[1] abc
# cleanup[1] _weakrefset
# cleanup[1] sre_constants
# cleanup[1] re
# cleanup[1] _codecs
# cleanup[1] _warnings
# cleanup[1] zipimport
# cleanup[1] _sysconfigdata
# cleanup[1] encodings.utf_8
# cleanup[1] codecs
# cleanup[1] readline
# cleanup[1] _locale
# cleanup[1] signal
# cleanup[1] traceback
# cleanup[1] posix
# cleanup[1] encodings.aliases
# cleanup[1] exceptions
# cleanup[1] _weakref
# cleanup[1] sre_compile
# cleanup[1] _sre
# cleanup[1] sre_parse
# cleanup[2] copy_reg
# cleanup[2] posixpath
# cleanup[2] errno
# cleanup[2] _abcoll
# cleanup[2] types
# cleanup[2] genericpath
# cleanup[2] stat
# cleanup[2] warnings
# cleanup[2] UserDict
# cleanup[2] os.path
# cleanup[2] linecache
# cleanup[2] os
# cleanup sys
# cleanup __builtin__
# cleanup ints: 19 unfreed ints
# cleanup floats
[root@ip-172-31-46-185 ~]# python -V
Python 2.7.12
[root@ip-172-31-46-185 ~]# /usr/bin/python -m pip install boto
Requirement already satisfied: boto in /usr/lib/python2.7/dist-packages
[root@ip-172-31-46-185 ~]# /usr/bin/python -m pip upgrade boto
ERROR: unknown command "upgrade"
[root@ip-172-31-46-185 ~]# /usr/bin/python -m pip install -U boto
Collecting boto
  Downloading boto-2.48.0-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 841kB/s
Installing collected packages: boto
  Found existing installation: boto 2.42.0
    Uninstalling boto-2.42.0:
      Successfully uninstalled boto-2.42.0
Successfully installed boto-2.48.0
[root@ip-172-31-46-185 ~]# ansible-playbook -i ./hosts ec2-basic.yml

PLAY [Provision an EC2 Instance] ****************************************************************************

TASK [Create a security group] ******************************************************************************
fatal: [localhost -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Region us-east-1b does                                                            not seem to be available for aws module boto.ec2. If the region definitely exists, you may need to upgrade b                                                           oto or extend with endpoints_path"}
        to retry, use: --limit @/root/ec2-basic.retry

PLAY RECAP **************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1

[root@ip-172-31-46-185 ~]# ansible-playbook -i ./hosts ec2-basic.yml

PLAY [Provision an EC2 Instance] *********************************************************************************************

TASK [Create a security group] ***********************************************************************************************
fatal: [localhost -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Region us-east-1b does not seem to be a                                          vailable for aws module boto.ec2. If the region definitely exists, you may need to upgrade boto or extend with endpoints_path"                                          }
        to retry, use: --limit @/root/ec2-basic.retry

PLAY RECAP *******************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1

[root@ip-172-31-46-185 ~]# vi ec2-basic.yml
[root@ip-172-31-46-185 ~]# ansible-playbook -i ./hosts ec2-basic.yml

PLAY [Provision an EC2 Instance] *********************************************************************************************

TASK [Create a security group] ***********************************************************************************************
changed: [localhost -> localhost]

TASK [Launch the new EC2 Instance] *******************************************************************************************
fatal: [localhost -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Instance creation failed => InvalidKeyP                                          air.NotFound: The key pair 'newkeyaug2017# This is one of my keys that i already have in AWS' does not exist"}
        to retry, use: --limit @/root/ec2-basic.retry

PLAY RECAP *******************************************************************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=1

[root@ip-172-31-46-185 ~]# vi ec2-basic.yml
[root@ip-172-31-46-185 ~]# ansible-playbook -i ./hosts ec2-basic.yml

PLAY [Provision an EC2 Instance] *********************************************************************************************

TASK [Create a security group] ***********************************************************************************************
ok: [localhost -> localhost]

TASK [Launch the new EC2 Instance] *******************************************************************************************
changed: [localhost -> localhost]

TASK [Add the newly created EC2 instance(s) to the local host group (located inside the directory)] **************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a vari                                          able that is undefined. The error was: 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'public_ip'\n\nTh                                          e error appears to have been in '/root/ec2-basic.yml': line 54, column 9, but may\nbe elsewhere in the file depending on the e                                          xact syntax problem.\n\nThe offending line appears to be:\n\n\n      - name: Add the newly created EC2 instance(s) to the loca                                          l host group (located inside the directory)\n        ^ here\n"}
        to retry, use: --limit @/root/ec2-basic.retry

PLAY RECAP *******************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=1

[root@ip-172-31-46-185 ~]# vi ec2-basic.yml
[root@ip-172-31-46-185 ~]# ansible-playbook -i ./hosts ec2-basic.yml

PLAY [Provision an EC2 Instance] *********************************************************************************************

TASK [Create a security group] ***********************************************************************************************
ok: [localhost -> localhost]

TASK [Launch the new EC2 Instance] *******************************************************************************************
changed: [localhost -> localhost]

TASK [Add the newly created EC2 instance to the local hosts] *****************************************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a vari                                          able that is undefined. The error was: 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'public_ip'\n\nTh                                          e error appears to have been in '/root/ec2-basic.yml': line 54, column 9, but may\nbe elsewhere in the file depending on the e                                          xact syntax problem.\n\nThe offending line appears to be:\n\n\n      - name: Add the newly created EC2 instance to the local h                                          osts\n        ^ here\n"}
        to retry, use: --limit @/root/ec2-basic.retry

PLAY RECAP *******************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=1

[root@ip-172-31-46-185 ~]# vi ec2-basic.yml
[root@ip-172-31-46-185 ~]# ansible-playbook -i ./hosts ec2-basic.yml

PLAY [Provision an EC2 Instance] *********************************************************************************************

TASK [Create a security group] ***********************************************************************************************
ok: [localhost -> localhost]

TASK [Launch the new EC2 Instance] *******************************************************************************************
changed: [localhost -> localhost]

TASK [Add the newly created EC2 instance] ************************************************************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a vari                                          able that is undefined. The error was: 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'public_ip'\n\nTh                                          e error appears to have been in '/root/ec2-basic.yml': line 54, column 9, but may\nbe elsewhere in the file depending on the e                                          xact syntax problem.\n\nThe offending line appears to be:\n\n\n      - name: Add the newly created EC2 instance\n        ^ her                                          e\n"}
        to retry, use: --limit @/root/ec2-basic.retry

PLAY RECAP *******************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=1

No comments:

Installing Ingress Controller - Kubernetes

Installing the Ingress Controller Prerequisites Make sure you have access to the Ingress controller image: For NGINX Ingress controll...