Skip to content

Commit

Permalink
Fix update-local-known-hosts on staging
Browse files Browse the repository at this point in the history
`hosts: localhost` apparently conflicts with `--limit !ansible_skip`
if `[ansible_skip]` is defined
  • Loading branch information
dannyroberts committed Jul 24, 2018
1 parent 69675d7 commit 4a61f59
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/commcare_cloud/commands/ansible/ansible_playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,29 @@ def modify_parser(self):
)
))

def run(self, args, unknown_args, always_skip_check=False):
def run(self, args, unknown_args, always_skip_check=False, respect_ansible_skip=True):
environment = get_environment(args.env_name)
environment.create_generated_yml()
ansible_context = AnsibleContext(args)
check_branch(args)
run_ansible_playbook(
return run_ansible_playbook(
environment, args.playbook, ansible_context, args.skip_check, args.quiet,
always_skip_check, args.limit, args.use_factory_auth, unknown_args
always_skip_check, args.limit, args.use_factory_auth, unknown_args,
respect_ansible_skip=respect_ansible_skip,
)


def run_ansible_playbook(
environment, playbook, ansible_context,
skip_check=False, quiet=False, always_skip_check=False, limit=None,
use_factory_auth=False, unknown_args=None
use_factory_auth=False, unknown_args=None, respect_ansible_skip=True,
):

def get_limit():
limit_parts = []
if limit:
limit_parts.append(limit)
if 'ansible_skip' in environment.sshable_hostnames_by_group:
if 'ansible_skip' in environment.sshable_hostnames_by_group and respect_ansible_skip:
limit_parts.append('!ansible_skip')

if limit_parts:
Expand Down Expand Up @@ -311,7 +312,8 @@ def run(self, args, unknown_args):
args.playbook = 'add-ssh-keys.yml'
args.quiet = True
environment = get_environment(args.env_name)
rc = AnsiblePlaybook(self.parser).run(args, unknown_args, always_skip_check=True)
rc = AnsiblePlaybook(self.parser).run(args, unknown_args, always_skip_check=True,
respect_ansible_skip=False)
with open(environment.paths.known_hosts, 'r') as f:
known_hosts = f.readlines()
known_hosts.sort()
Expand Down

0 comments on commit 4a61f59

Please sign in to comment.